-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathapp.py
More file actions
47 lines (36 loc) · 1.46 KB
/
Copy pathapp.py
File metadata and controls
47 lines (36 loc) · 1.46 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import time
from dotenv import load_dotenv
import azure.cognitiveservices.speech as speechsdk
# Load the speech key and region from the .env file
load_dotenv()
key = os.getenv("KEY")
region = os.getenv("REGION")
stop = False
# When a sentence is recognized, print it to the screen.
# If stop is said, stop the app
def recognized(args):
global stop
print(args.result.text)
if args.result.text == "Stop.":
stop = True
# Create a speech configuration using the following:
# The API key and region loaded from the .env file
# The language that will be recognized, in this example Great British English (en-GB)
#
# See https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support?WT.mc_id=build2020_ca-github-jabenn
# for the list of supported languages that can be recognized
speech_config = speechsdk.SpeechConfig(subscription=key,
region=region,
speech_recognition_language="en-GB")
# Create a speech recognizer
recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
# Connect up the recognized event
recognizer.recognized.connect(recognized)
# Start continuous recognition
# This happens in the background, so the app continues to run, hence the need for an infinite loop
recognizer.start_continuous_recognition()
print("Say something! Say stop when you are done.")
# Loop until we hear stop
while not stop:
time.sleep(0.1)