【问题标题】:Calling SpeechAPI for text to speech on Azure在 Azure 上调用 SpeechAPI 以实现文本转语音
【发布时间】:2016-03-13 00:27:22
【问题描述】:

我在本地服务器上运行了以下非常基本的 TTS 代码

using System.Speech.Synthesis;
...
SpeechSynthesizer reader = new SpeechSynthesizer();
reader.Speak("This is a test");

此代码依赖于 System.Speech,我在 VS 2015 项目中为此添加了参考。 工作正常,但根据我的阅读和尝试,我知道当代码托管在 Azure 上时,这将不起作用。 我已经阅读了几篇关于 SO 查询的帖子,是否真的可以在 azure 上进行 TTS。当然,在 2 年前,这似乎是不可能的。 How to get System.Speech on windows azure websites?

似乎所有的道路都通向 Microsoft Speech API https://azure.microsoft.com/en-gb/marketplace/partners/speechapis/speechapis/ 我已经注册并获得了用于调用此 API 的私钥和 sec 密钥。 然而我的问题是这个。我如何实际调用 SpeechAPI?我必须在上面的简单代码示例中进行哪些更改,以便在 azure 上运行时可以正常工作?

【问题讨论】:

    标签: c# azure microsoft-speech-api


    【解决方案1】:

    您在 Azure 市场中提到的语音 API 是一个名为 ProjectOxford 的 AI 微软项目的一部分,该项目提供了一系列用于计算机视觉、语音和语言的 API。

    这些都是 RESTful API,这意味着您将构建 HTTP 请求以发送到云中的托管在线服务。 语音转文本文档在here 可用,您可以在 github 上找到各种客户端的示例代码。专门针对 C#,您可以在 this sample project 中看到一些代码。

    请注意,ProjectOxford 仍处于预览阶段(测试版)。可以在ProjectOxford MSDN forum 上找到使用这些 API 的更多支持。

    但只是为了让您了解程序的外观(取自 github 上的上述代码示例):

            AccessTokenInfo token;
    
            // Note: Sign up at http://www.projectoxford.ai for the client credentials.
            Authentication auth = new Authentication("Your ClientId goes here", "Your Client Secret goes here");
    
            ... 
    
            token = auth.GetAccessToken();
    
            ...
    
            string requestUri = "https://speech.platform.bing.com/synthesize";
    
            var cortana = new Synthesize(new Synthesize.InputOptions()
            {
                RequestUri = new Uri(requestUri),
                // Text to be spoken.
                Text = "Hi, how are you doing?",
                VoiceType = Gender.Female,
                // Refer to the documentation for complete list of supported locales.
                Locale = "en-US",
                // You can also customize the output voice. Refer to the documentation to view the different
                // voices that the TTS service can output.
                VoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)",
                // Service can return audio in different output format. 
                OutputFormat = AudioOutputFormat.Riff16Khz16BitMonoPcm,
                AuthorizationToken = "Bearer " + token.access_token,
            });
    
            cortana.OnAudioAvailable += PlayAudio;
            cortana.OnError += ErrorHandler;
            cortana.Speak(CancellationToken.None).Wait();
    

    【讨论】:

    • 谢谢,我没有意识到它还处于测试阶段。在阅读了 Azure 网站上的定价后,我们目前处理的语音请求数量将花费我们近 100 万美元(每年 2.5 亿次,我们在 AWS EC2 实例中花费大约 50K 来提供相同的服务)所以我试图验证我是否正确阅读了定价信息,后来来自 3 个不同的人的 3 封电子邮件,我发现自己被引导回到他们的 azure 定价页面,抱歉,“我们不确定”。看起来 Azure 并不适合我们的特定用例 :(
    • 您指的是哪个定价网站? ProjectOxford 定价可在此处找到:projectoxford.ai/pricing
    • 请注意,由于它是预览版,这些 API 的定价可能会发生变化。无论如何,如果您在 EC2 实例上使用其他方法来处理这些并考虑迁移到 Azure,那么它的价值也可以在这里与 Azure VM 定价进行比较:azure.microsoft.com/en-us/pricing/calculator 这将是一个更“苹果”与“苹果”的比较跨度>
    猜你喜欢
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多