speech_recognize_continuous_from_file : how to print all results together in a text file
See original GitHub issue# coding: utf-8
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
import time
import wave
try:
import azure.cognitiveservices.speech as speechsdk
except ImportError:
print("""
Importing the Speech SDK for Python failed.
Refer to
https://docs.microsoft.com/azure/cognitive-services/speech-service/quickstart-python for
installation instructions.
""")
import sys
sys.exit(1)
# Set up the subscription info for the Speech Service:
# Replace with your own subscription key and service region (e.g., "westus").
speech_key, service_region = "key", "region"
# Specify the path to an audio file containing speech (mono WAV / PCM with a sampling rate of 16
# kHz).
hindi = "C:/Users/Khushboo.Girotra/Desktop/audionew1.wav"
def speech_recognize_continuous_from_file():
"""performs continuous speech recognition with input from an audio file"""
# <SpeechContinuousRecognitionWithFile>
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region, speech_recognition_language='hi-IN')
audio_config = speechsdk.audio.AudioConfig(filename=hindi)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
done = False
def stop_cb(evt):
"""callback that stops continuous recognition upon receiving an event `evt`"""
print('CLOSING on {}'.format(evt))
speech_recognizer.stop_continuous_recognition()
nonlocal done
done = True
# Connect callbacks to the events fired by the speech recognizer
speech_recognizer.recognizing.connect(lambda evt: print('RECOGNIZING: {}'.format(evt)))
all_results = []
def handle_final_result(evt):
all_results.append(evt.result.text)
speech_recognizer.recognized.connect(handle_final_result)
speech_recognizer.start_continuous_recognition()
print(all_results)
speech_recognizer.recognized.connect(lambda evt: print('RECOGNIZED: {}'.format(evt)))
speech_recognizer.session_started.connect(lambda evt: print('SESSION STARTED: {}'.format(evt)))
speech_recognizer.session_stopped.connect(lambda evt: print('SESSION STOPPED {}'.format(evt)))
speech_recognizer.canceled.connect(lambda evt: print('CANCELED {}'.format(evt)))
# stop continuous recognition on either session stopped or canceled events
speech_recognizer.session_stopped.connect(stop_cb)
speech_recognizer.canceled.connect(stop_cb)
#speech_recognizer.start_continuous_recognition()
# Start continuous speech recognition
speech_recognizer.start_continuous_recognition()
while not done:
time.sleep(.5)
# </SpeechContinuousRecognitionWithFile>```
**Above code is not working
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
python - How to store speech recognition output in a text file
I need the words appended every time ( while the script runs continuously ). Many thanks for any help. import speech_recognition as sr...
Read more >How to save speech to text output using continuous ...
Hi, I'm using Speech to Text on a *.wav file from within the Azure ... Close the output file and stop the continuous...
Read more >"Easy" Computer Speech Recognition with Azure ... - YouTube
Cognitive Services brings AI within reach of every ... Raspberry Pi with Azure/ Python Speech to Text from File Can be read out...
Read more >Real-Time Speech Recognition With Your Microphone ...
By the end, you'll have a fully working Jupyter notebook that can record microphone audio, transcribe it, and display it.
Read more >The Ultimate Guide To Speech Recognition With Python
An in-depth tutorial on speech recognition with Python. Learn which speech recognition library gives the best results and build a full-featured "Guess The ......
Read more >Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi , Kindly help!
You can use standard Python methods to save the text to a file, i.e.
Please note that this forum is primarily for SDK-related issues, not for general programming questions (try for example stackoverflow for these), so I’m closing this issue.