4
import azure.cognitiveservices.speech as speechsdk
speech_key="speech key"
service_region="eastus"

def speech_synthesis_with_auto_language_detection_to_speaker(text):
    """performs speech synthesis to the default speaker with auto language detection
       Note: this is a preview feature, which might be updated in future versions."""
    speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

    # create the auto detection language configuration without specific languages
    auto_detect_source_language_config = speechsdk.languageconfig.AutoDetectSourceLanguageConfig()

    # Creates a speech synthesizer using the default speaker as audio output.
    speech_synthesizer = speechsdk.SpeechSynthesizer(
        speech_config=speech_config, auto_detect_source_language_config=auto_detect_source_language_config)

    result = speech_synthesizer.speak_text_async(text).get()
        # Check result
    if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
            print("Speech synthesized to speaker for text [{}]".format(text))
            stream = speechsdk.AudioDataStream(result)
            stream.save_to_wav_file(r"C:\Users\user\Desktop\outputfff.wav")

speech_synthesis_with_auto_language_detection_to_speaker("तू कसा आहेस ")

How to just save file directly to wave without speaking it please help

as if you can see the documentation of azure cognitive services they dont add this about how to just save also the speech_synthesizer calss also dont have any method for just save file without play it

1 Answers1

3

Try this:

import azure.cognitiveservices.speech as speechsdk
speech_key=""
service_region=""

def speech_synthesis_with_auto_language_detection_to_speaker(text):
    """performs speech synthesis to the default speaker with auto language detection
       Note: this is a preview feature, which might be updated in future versions."""
    speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

    # create the auto detection language configuration without specific languages
    auto_detect_source_language_config = speechsdk.languageconfig.AutoDetectSourceLanguageConfig()

    # Creates a speech synthesizer using the default speaker as audio output.
    speech_synthesizer = speechsdk.SpeechSynthesizer(
        speech_config=speech_config, auto_detect_source_language_config=auto_detect_source_language_config,audio_config=None)

    result = speech_synthesizer.speak_text_async(text).get();
        # Check result
    if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
            print("Speech synthesized to speaker for text [{}]".format(text))
            stream = speechsdk.AudioDataStream(result)
            stream.save_to_wav_file(r"C:\Users\user\Desktop\outputfff.wav")

speech_synthesis_with_auto_language_detection_to_speaker("तू कसा आहेस ")

Just specify audio_config=None for speechsdk.SpeechSynthesizer.

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • Thank you Stanely just one more question related to it when i try to use this code in Cent Os it gives "Import Error: version `CXXABI_1.3.9' not found" – Sachin Anbhule Nov 25 '20 at 08:32
  • @SachinAnbhule, Welcome, but I am sorry,I am not quite sure about your second question. Could you please post another question with detailed information ? On stack overfolow ,it is one case one question,thanks ! – Stanley Gong Nov 25 '20 at 08:36
  • thank you so much Stanely,I already solved that error – Sachin Anbhule Nov 25 '20 at 11:40
  • Thank you @Stanley. I am completely new to this. While i was executing your code , i got below error ""AttributeError: module 'azure.cognitiveservices.speech' has no attribute 'SpeechSynthesizer'".Could you please guide me. I have installed the azure-cognitiveservices-speech-1.15.0 version. – ssp Feb 05 '21 at 10:50