hojin
hojin

Reputation: 13

How to save converted text data from azure cognitive services?

I'm currently having a hard time saving the result of the speech to text from Microsoft azure cognitive service API.

This is my code.

import azure.cognitiveservices.speech as speechsdk
import time

# Creates an instance of a speech config with specified subscription key and service region.
# Replace with your own subscription key and service region (e.g., "westus").
speech_key, service_region = "speech_key", "region"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

# Creates a recognizer with the given settings

speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region, speech_recognition_language="it-IT")
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)

speech_recognizer.session_started.connect(lambda evt: print('SESSION STARTED: {}'.format(evt)))
speech_recognizer.session_stopped.connect(lambda evt: print('\nSESSION STOPPED {}'.format(evt)))
speech_recognizer.recognized.connect(lambda evt: print('\n{}'.format(evt.result.text)))

print('Say a few words\n\n')
result = speech_recognizer.recognize_once_async().get()
print(result.text)

speech_recognizer.start_continuous_recognition()
time.sleep(10)
speech_recognizer.stop_continuous_recognition()

speech_recognizer.session_started.disconnect_all()
speech_recognizer.recognized.disconnect_all()
speech_recognizer.session_stopped.disconnect_all()

I wanted to save the converted text from speech-to-text API. I already had a subscription key and region, but have no clue how to save the data to JSON file.

Upvotes: 1

Views: 388

Answers (1)

Ram
Ram

Reputation: 2754

The result.Text returns the recognized text in the result, you can save to the file.

In Python this repo added some sample code to demo the Speech to Text SDK: https://github.com/caiomsouza/Microsoft-Cognitive-Services/tree/master/speech-to-text and this python code is converting any audio files size.

Upvotes: 0

Related Questions