def transcribe_watson(loop, src, src_freq, username, password): ts = transcriber.WatsonTranscriber(src, src_freq, user=username, password=password) ts.register_event_handler(handle_transcribe_event) loop.run_until_complete(ts.transcribe())
async def test_transcribe(self): with mock.patch('websockets.connect') as mock_ws: fake_ws = FakeWatsonWS() mock_ws.return_value = fake_ws.connect() ts = transcriber.WatsonTranscriber(audio_fakes.SilentAudioSource(), 16000, 'fakeuser', 'fakepass') handler = EvHandler(ts) ts.register_event_handler(handler.handle) async with ts: await handler.called.wait()
def transcribe_wav_file(path, watson_user, watson_pass): # Create an audio source from the wav file wav_src = audio.WaveSource(path) # Create a transcriber for watson which will read from our audio source ts = transcriber.WatsonTranscriber(wav_src, 44100, watson_user, watson_pass) # Register our handle_event method to be called when transcription occurs ts.register_event_handler(handle_event) # Run transcription loop = asyncio.get_event_loop() loop.run_until_complete(ts.transcribe())
def cmd_transcribe(args): try: user = os.environ['WATSON_SST_USER'] passwd = os.environ['WATSON_SST_PASSWORD'] except KeyError: raise CommandError('Missing WATSON_SST_USER or WATSON_SST_PASSWORD ' 'environment variable.') mic = hello_wave_source() squelched = audio.SquelchedSource(mic, squelch_level=500) loop = asyncio.get_event_loop() ts = transcriber.WatsonTranscriber(squelched, 44100, user=user, passwd=passwd) tasks = [ asyncio.ensure_future(ts.transcribe()), asyncio.ensure_future(handle_events(ts)), ] loop.run_until_complete(asyncio.gather(*tasks))
def transcribe(args): loop = asyncio.get_event_loop() src = get_audio_source(args.channels, args.frequency, args.device_index) if not args.no_squelch: squelch_level = None if args.squelch_level: squelch_level = args.squelch_level src = audio.SquelchedSource(src, squelch_level=squelch_level) if not args.squelch_level: print('Detecting squelch level.') print('Please talk in to your microphone at a normal volume.') loop.run_until_complete(src.detect_squelch_level()) print('Completed detection squelch level.') ts = None service = args.transcription_service if service == 'watson': username = os.environ.get('WATSON_SST_USER') or args.username password = os.environ.get('WATSON_SST_PASSWORD') or args.password if not username: exit(error='You must specify a username.') if not password: exit(error='You must specify a password.') print('Beginning transcription.') ts = transcriber.WatsonTranscriber(src, args.frequency, user=username, password=password) elif service == 'pocketsphinx': ts = transcriber.PocketSphinxTranscriber.default_config(src) else: raise RuntimeError('Invalid service') ts.register_event_handler(handle_transcribe_event) loop.run_until_complete(run_transcription(ts))