async def _capture_offline(self, sound_device: str, started_future: asyncio.Future, loop): try: stream = MicrophoneStreaming(buffersize=self._block_size, loop=loop) async for block, status in stream.generator(started_future): try: self._buffer_queue.put_nowait(block) except asyncio.QueueFull as fullErr: logger.warning("The audio buffer queue is too full.") raise fullErr except MicrophoneCaptureFailed as captureErr: logger.error("Unable to capture from {0}", sound_device) raise captureErr except RuntimeError as rerr: logger.error("RuntimeError in capture and transcribe") raise rerr
async def main(): loop = asyncio.get_running_loop() stream = MicrophoneStreaming(buffersize=args.blocksize, loop=loop) async for transcription in wavenet.capture_and_transcribe(stream, loop=loop): if not transcription == "": print_func = functools.partial(print_transcription, transcription=transcription) await loop.run_in_executor(None, print_func)
async def _capture_and_transcribe(self, sound_device: str, started_future: asyncio.Future, loop): try: stream = MicrophoneStreaming(buffersize=self._block_size, loop=loop) # consuming the audio capture stream and online transcription async for transcribed in self._asr.capture_and_transcribe( stream, started_future, loop=loop): if not transcribed == "": try: self._transcription_queue.put_nowait(transcribed) except asyncio.QueueFull as fullErr: logger.warning("The transcription queue is too full.") raise fullErr except MicrophoneCaptureFailed as captureErr: logger.error("Unable to capture from {0}", sound_device) raise captureErr except RuntimeError as rerr: logger.error("RuntimeError in capture and transcribe") raise rerr
async def capture(): stream = MicrophoneStreaming() async for block, status in stream.generator(): # process data here print(len(block))
async def save_audio(): stream = MicrophoneStreaming() await stream.record_to_file(filename=filename, duration=duration)