【问题标题】:How Microsoft Azure text to Speech without speaking just save file directly?Microsoft Azure text to Speech 如何不说话直接保存文件?
【发布时间】:2021-03-08 00:03:42
【问题描述】:
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 也没有任何方法可以仅保存文件而不播放它

【问题讨论】:

    标签: python python-3.x azure text-to-speech azure-cognitive-services


    【解决方案1】:

    试试这个:

    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

    【讨论】:

    • 谢谢你,当我尝试在 Cent Os 中使用此代码时,我又遇到了一个与此相关的问题,它给出“导入错误:未找到版本‘CXXABI_1.3.9’”
    • @SachinAnbhule,欢迎您,但很抱歉,我不太确定您的第二个问题。您能否发布另一个包含详细信息的问题?关于堆栈溢出,这是一个案例一的问题,谢谢!
    • 非常感谢 Stanely,我已经解决了这个错误
    • 谢谢@Stanley。我对此完全陌生。在执行您的代码时,出现以下错误““AttributeError:模块'azure.cognitiveservices.speech'没有属性'SpeechSynthesizer'”。请您指导我。我已经安装了azure-cognitiveservices-speech-1.15.0版本。
    猜你喜欢
    • 2019-08-11
    • 1970-01-01
    • 2019-05-03
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    相关资源
    最近更新 更多