The following code shows how to call the microsoft Azure text to speech service in an continuous or streaming way. The audio input is from default microphone.
import azure.cognitiveservices.speech as speechsdk
def recognized_handler(evt): # This handler is for final results if evt.result.reason == speechsdk.ResultReason.RecognizedSpeech: print(f"Final result: {evt.result.text}")
def recognizing_handler(evt): # This handler is for partial results #print(evt.result) if evt.result.reason == speechsdk.ResultReason.RecognizingSpeech: print(f"Partial result: {evt.result.text}")
# Start continuous speech recognition speech_recognizer.start_continuous_recognition() try: while True: # Keep the main thread alive while the background thread processes the speech recognition pass except KeyboardInterrupt: # Stop recognition when Ctrl+C is pressed speech_recognizer.stop_continuous_recognition()
Reprint policy:
All articles in this blog are used except for special statements
CC BY 4.0
reprint policy. If reproduced, please indicate source
robot learner
!