You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
925 B
33 lines
925 B
import json
|
|
import time
|
|
from azure.cognitiveservices.speech import SpeechConfig, SpeechRecognizer
|
|
from azure.iot.device import IoTHubDeviceClient, Message
|
|
|
|
api_key = '<key>'
|
|
location = '<location>'
|
|
language = '<language>'
|
|
connection_string = '<connection_string>'
|
|
|
|
device_client = IoTHubDeviceClient.create_from_connection_string(connection_string)
|
|
|
|
print('Connecting')
|
|
device_client.connect()
|
|
print('Connected')
|
|
|
|
speech_config = SpeechConfig(subscription=api_key,
|
|
region=location,
|
|
speech_recognition_language=language)
|
|
|
|
recognizer = SpeechRecognizer(speech_config=speech_config)
|
|
|
|
def recognized(args):
|
|
if len(args.result.text) > 0:
|
|
message = Message(json.dumps({ 'speech': args.result.text }))
|
|
device_client.send_message(message)
|
|
|
|
recognizer.recognized.connect(recognized)
|
|
|
|
recognizer.start_continuous_recognition()
|
|
|
|
while True:
|
|
time.sleep(1) |