在Azure上调用SpeechAPI进行文本到语音转换 [英] Calling SpeechAPI for text to speech on Azure

查看:673
本文介绍了在Azure上调用SpeechAPI进行文本到语音转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following very basic TTS code running on my local server

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

此代码依赖于System.Speech,为此我在VS 2015项目中添加了参考. 工作正常,但是根据我的阅读和尝试,我知道当代码托管在Azure上时,这将无法正常工作. 我已经阅读了几则关于SO查询的帖子,如果实际上有可能在天蓝色的情况下执行TTS.肯定在2年之前,这似乎是不可能的. 如何在Windows Azure网站上获取System.Speech?

This code has a dependency on System.Speech for which I have added a Reference in my VS 2015 project. Works fine but from what I have read and from trying it I know this will not work when the code is hosted on Azure. I have read several posts on SO querying if it is actually possible to do TTS on azure. Certainly 2 yrs ago it did not appear to be possible. 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上运行时可以正常工作?

All roads seem to lead to the Microsoft Speech API https://azure.microsoft.com/en-gb/marketplace/partners/speechapis/speechapis/ I have signed up and have gotten my private and sec keys for calling into this API. However my question is this. How do I actually call the SpeechAPI? What do I have to change in the simple code example above so that this will work when running on azure?

推荐答案

您在Azure市场上引用的语音API是名为

The speech API you referred to at the Azure marketplace is part of an AI Microsoft project called ProjectOxford which offers an array of APIs for computer vision, speech and language.

所有这些都是RESTful API,这意味着您将构建HTTP请求以发送到云中托管的在线服务. 您可以在此处获得语音转文本文档,并可以找到示例github上的各种客户端的代码.专门针对C#,您可以在此示例中看到一些代码项目.

These are all RESTful APIs, meaning that you will be constructing HTTP requests to send to a hosted online service in the cloud. The speech-to-text documentation is available here and you can find sample code for various clients on github. Specifically for C# you can see some code in this sample project.

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

Please note that ProjectOxford is still in preview (Beta). Additional support for using these APIs can be found on the ProjectOxford MSDN forum.

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

But just to give you an idea of how your program will look like (taken from the above code sample on 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上调用SpeechAPI进行文本到语音转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆