The steps for this recipe are as follows:
- Import the libraries:
import azure.cognitiveservices.speech as speechsdk
import time
- Import the key that was generated in the Getting ready section:
speech_key, service_region = "Your Key", "westus2"
- Initialize the speech service:
speech_config = speechsdk.SpeechConfig(subscription=speech_key,
region=service_region)
speech_recognizer = \
speechsdk.SpeechRecognizer(speech_config=speech_config)
speech_recognizer.session_started.connect(lambda evt: \
print('SESSION STARTED: {}'.format(evt)))
speech_recognizer.session_stopped.connect(lambda evt: \
print('\nSESSION STOPPED {}'.format(evt)))
speech_recognizer.recognized.connect(lambda evt: \
print('\n{}'.format(evt.result.text)))
- Then, perform continuous speech recognition by using an infinite loop:
try:
while True:
speech_recognizer.start_continuous_recognition()
time...