def send_audio(self, ws):
        """
        Stream audio to server

        :param ws: Websocket client
        """
        def run(*args):
            """Background process to stream the data"""
            if not self.audio_source.is_buffer:
                while True:
                    chunk = self.audio_source.input.read(ONE_KB)
                    if not chunk:
                        break
                    self.ws_client.send(chunk, websocket.ABNF.OPCODE_BINARY)
                    time.sleep(TEN_MILLISECONDS)

                self.audio_source.input.close()
            else:
                while True:
                    try:
                        if not self.audio_source.input.empty():
                            chunk = self.audio_source.input.get()
                            self.ws_client.send(chunk, websocket.ABNF.OPCODE_BINARY)
                            time.sleep(TEN_MILLISECONDS)
                        if self.audio_source.input.empty():
                            if self.audio_source.is_recording:
                                time.sleep(TEN_MILLISECONDS)
                            else:
                                break
                    except Exception:
                        if self.audio_source.is_recording:
                            time.sleep(TEN_MILLISECONDS)
                        else:
                            break

            time.sleep(TEN_MILLISECONDS)
            self.ws_client.send(self.build_closing_message(), websocket.ABNF.OPCODE_TEXT)

        thread.start_new_thread(run, ())
def send_audio ( self , ws ) : def run ( * args ) : if not self . audio_source . is_buffer : while True : chunk = self . audio_source . input . read ( ONE_KB ) if not chunk : break self . ws_client . send ( chunk , websocket . ABNF . OPCODE_BINARY ) time . sleep ( TEN_MILLISECONDS ) self . audio_source . input . close ( ) else : while True : try : if not self . audio_source . input . empty ( ) : chunk = self . audio_source . input . get ( ) self . ws_client . send ( chunk , websocket . ABNF . OPCODE_BINARY ) time . sleep ( TEN_MILLISECONDS ) if self . audio_source . input . empty ( ) : if self . audio_source . is_recording : time . sleep ( TEN_MILLISECONDS ) else : break except Exception : if self . audio_source . is_recording : time . sleep ( TEN_MILLISECONDS ) else : break time . sleep ( TEN_MILLISECONDS ) self . ws_client . send ( self . build_closing_message ( ) , websocket . ABNF . OPCODE_TEXT ) thread . start_new_thread ( run , ( ) )
Stream audio to server

        :param ws: Websocket client