【问题标题】:Get Speech Studio files from Azure Cognitive Text to Speech API (or SDK)从 Azure Cognitive Text to Speech API(或 SDK)获取 Speech Studio 文件
【发布时间】:2022-12-14 01:59:50
【问题描述】:

有什么方法可以使用 REST API 或 SDK 获取在 Speech Studio 中生成的文件?

我正在做一个项目,我想从文本创建多个音频,我喜欢 Speech Studio 工具,所以我们正在考虑将它集成到工作流程中,在 Speech Studio 中创建音频,然后在应用程序中请求它们。

【问题讨论】:

    标签: text-to-speech azure-cognitive-services azure-speech


    【解决方案1】:

    没有用于导出音频的 APIAzure Speech Studio 音频创建中心.但您可以直接通过 API/SDK 生成音频并将其导出。

    API 示例 -

     curl --location --request POST "https://${SPEECH_REGION}.tts.speech.microsoft.com/cognitiveservices/v1" 
    --header "Ocp-Apim-Subscription-Key: ${SPEECH_KEY}" 
    --header 'Content-Type: application/ssml+xml' 
    --header 'X-Microsoft-OutputFormat: audio-16khz-128kbitrate-mono-mp3' 
    --header 'User-Agent: curl' 
    --data-raw '<speak version='''1.0''' xml:lang='''en-US'''>
        <voice xml:lang='''en-US''' xml:gender='''Female''' name='''en-US-JennyNeural'''>
            my voice is my passport verify me
        </voice>
    </speak>' > output.mp3
    

    Python 开发工具包示例

    import os
    import azure.cognitiveservices.speech as speechsdk
    
    # This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
    speech_config = speechsdk.SpeechConfig(subscription=os.environ.get('SPEECH_KEY'), region=os.environ.get('SPEECH_REGION'))
    audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)
    
    # The language of the voice that speaks.
    speech_config.speech_synthesis_voice_name='en-US-JennyNeural'
    
    speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
    
    # Get text from the console and synthesize to the default speaker.
    print("Enter some text that you want to speak >")
    text = input()
    
    speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()
    
    if speech_synthesis_result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
        print("Speech synthesized for text [{}]".format(text))
    elif speech_synthesis_result.reason == speechsdk.ResultReason.Canceled:
        cancellation_details = speech_synthesis_result.cancellation_details
        print("Speech synthesis canceled: {}".format(cancellation_details.reason))
        if cancellation_details.reason == speechsdk.CancellationReason.Error:
            if cancellation_details.error_details:
                print("Error details: {}".format(cancellation_details.error_details))
                print("Did you set the speech resource key and region values?")
    

    更多例子和方法可以参考-https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-python#synthesize-to-a-file

    在工作室中,导出音频的唯一方法是“导出”按钮

    【讨论】:

      猜你喜欢
      • 2019-05-03
      • 2016-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      相关资源
      最近更新 更多