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