4 examples of 'speech recognition module python' in Python

Every line of 'speech recognition module python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
238def main():
239 """start bidirectional streaming from microphone input to speech API"""
240
241 client = speech.SpeechClient()
242 config = speech.types.RecognitionConfig(
243 encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
244 sample_rate_hertz=SAMPLE_RATE,
245 language_code='en-US',
246 max_alternatives=1)
247 streaming_config = speech.types.StreamingRecognitionConfig(
248 config=config,
249 interim_results=True)
250
251 mic_manager = ResumableMicrophoneStream(SAMPLE_RATE, CHUNK_SIZE)
252 print(mic_manager.chunk_size)
253 sys.stdout.write(YELLOW)
254 sys.stdout.write('\nListening, say "Quit" or "Exit" to stop.\n\n')
255 sys.stdout.write('End (ms) Transcript Results/Status\n')
256 sys.stdout.write('=====================================================\n')
257
258 with mic_manager as stream:
259
260 while not stream.closed:
261 sys.stdout.write(YELLOW)
262 sys.stdout.write('\n' + str(
263 STREAMING_LIMIT * stream.restart_counter) + ': NEW REQUEST\n')
264
265 stream.audio_input = []
266 audio_generator = stream.generator()
267
268 requests = (speech.types.StreamingRecognizeRequest(
269 audio_content=content)for content in audio_generator)
270
271 responses = client.streaming_recognize(streaming_config,
272 requests)
273
274 # Now, put the transcription responses to use.
275 listen_print_loop(responses, stream)
276
277 if stream.result_end_time > 0:
278 stream.final_request_end_time = stream.is_final_end_time
279 stream.result_end_time = 0
280 stream.last_audio_input = []
281 stream.last_audio_input = stream.audio_input
282 stream.audio_input = []
283 stream.restart_counter = stream.restart_counter + 1
284
285 if not stream.last_transcript_was_final:
286 sys.stdout.write('\n')
287 stream.new_stream = True
47def main():
48 """Run all checks and print status."""
49 if not os.path.exists(CREDENTIALS_PATH):
50 print(
51 """Please follow the Custom Voice User Interface instructions on the AIY website
52to download credentials:
53https://aiyprojects.withgoogle.com/voice-v1/#makers-guide-3-custom-voice-user-interface
54and save them to""", CREDENTIALS_PATH)
55 return
56
57 if not check_credentials_valid():
58 print(
59 CREDENTIALS_PATH, """is not valid, please check that you have downloaded JSON
60service credentials.""")
61 return
62
63 if not check_speech_reco():
64 print('Failed to test the Cloud Speech API. Please see error above.')
65 return
66
67 print("Everything is set up to use the Google Cloud.")
31def test_google_chinese(self):
32 r = sr.Recognizer()
33 with sr.AudioFile(self.AUDIO_FILE_ZH) as source: audio = r.record(source)
34 self.assertEqual(r.recognize_google(audio, language="zh-CN"), u"砸自己的脚")
54def speech_synthesis_with_language():
55 """performs speech synthesis to the default speaker with specified spoken language"""
56 # Creates an instance of a speech config with specified subscription key and service region.
57 speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
58 # Sets the synthesis language.
59 # The full list of supported languages can be found here:
60 # https://docs.microsoft.com/azure/cognitive-services/speech-service/language-support#text-to-speech
61 language = "de-DE";
62 speech_config.speech_synthesis_language = language
63 # Creates a speech synthesizer for the specified language,
64 # using the default speaker as audio output.
65 speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
66
67 # Receives a text from console input and synthesizes it to speaker.
68 while True:
69 print("Enter some text that you want to speak, Ctrl-Z to exit")
70 try:
71 text = input()
72 except EOFError:
73 break
74 result = speech_synthesizer.speak_text_async(text).get()
75 # Check result
76 if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
77 print("Speech synthesized to speaker for text [{}] with language [{}]".format(text, language))
78 elif result.reason == speechsdk.ResultReason.Canceled:
79 cancellation_details = result.cancellation_details
80 print("Speech synthesis canceled: {}".format(cancellation_details.reason))
81 if cancellation_details.reason == speechsdk.CancellationReason.Error:
82 print("Error details: {}".format(cancellation_details.error_details))

Related snippets