Spaces:
Sleeping
Sleeping
File size: 1,168 Bytes
d8682b4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import azure.cognitiveservices.speech as speechsdk
# Azure credentials
speech_key = "12afe22c558a4f8d8bd28d6a67cdb9b0"
service_region = "westus"
def test_speech_sdk():
try:
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
print("Say something...")
result = speech_recognizer.recognize_once()
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
print(f"Recognized: {result.text}")
elif result.reason == speechsdk.ResultReason.NoMatch:
print("No speech could be recognized")
elif result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
print(f"Speech Recognition canceled: {cancellation_details.reason}")
print(f"Error details: {cancellation_details.error_details}")
except Exception as e:
print(f"An error occurred: {e}")
test_speech_sdk()
|