Microsoft Azure text to Speech 如何不说话直接保存文件?

How Microsoft Azure text to Speech without speaking just save file directly?

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("तू कसा आहेस ")

如何不说话直接保存文件到wave请帮忙

好像你可以看到 azure 认知服务的文档,他们没有添加关于如何只保存 speech_synthesizer calss 也没有任何方法只保存文件而不播放它

试试这个:

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("तू कसा आहेस ")

只需为 speechsdk.SpeechSynthesizer 指定 audio_config=None