question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Khushu06commented, Aug 17, 2019

Hi , Kindly help!

0reactions
chlandsicommented, Aug 19, 2019

You can use standard Python methods to save the text to a file, i.e.

with open('output.txt') as f:
    f.write('\n'.join(all_results))

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found