gpt4 book ai didi

c# - 在 Azure 上调用 SpeechAPI 进行文本转语音

转载 作者:行者123 更新时间:2023-11-30 16:49:47 26 4
gpt4 key购买 nike

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

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

此代码依赖于 System.Speech,我已在 VS 2015 项目中添加了引用。工作正常,但从我读过的内容和尝试来看,我知道当代码托管在 Azure 上时,这将不起作用。我读过几篇关于SO查询是否真的可以在azure上进行TTS的文章。当然,两年前这似乎是不可能的。 How to get System.Speech on windows azure websites?

条条大路似乎都通 Microsoft Speech API https://azure.microsoft.com/en-gb/marketplace/partners/speechapis/speechapis/我已经注册并获得了用于调用此 API 的私钥和安全 key 。然而我的问题是这样的。我如何实际调用 SpeechAPI?我必须在上面的简单代码示例中更改哪些内容才能在 Azure 上运行时正常工作?

最佳答案

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

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

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

但只是为了让您了解您的程序的外观(取自 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();

关于c# - 在 Azure 上调用 SpeechAPI 进行文本转语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35965060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com