Spaces:
Sleeping
Sleeping
| 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() | |