简体   繁体   English

Web 应用程序中的 Azure 文本转语音(认知服务) - 如何阻止它输出音频?

[英]Azure Text to Speech (Cognitive Services) in web app - how to stop it from outputting audio?

I'm using Azure Cognitive Services for Text to Speech in a web app.我在 Web 应用中使用 Azure 文本转语音认知服务。

I return the bytes to the browser and it works great, however on the server (or local machine) the speechSynthesizer.SpeakTextAsync(inp) line outputs the audio to the speaker.我将字节返回给浏览器并且效果很好,但是在服务器(或本地计算机)上, speechSynthesizer.SpeakTextAsync(inp)行将音频输出到扬声器。

Is there a way to turn this off, since this runs on a web server (and even if I ignore it, there's the delay while it outputs audio before sending back the data)有没有办法关闭它,因为它在网络服务器上运行(即使我忽略它,它在发送回数据之前输出音频时也会有延迟)

Here's my code...这是我的代码...

            var speechConfig = SpeechConfig.FromSubscription(speechKey, speechRegion);

            speechConfig.SpeechSynthesisVoiceName = "fa-IR-FaridNeural";
            speechConfig.OutputFormat = OutputFormat.Detailed;

            using (var speechSynthesizer = new SpeechSynthesizer(speechConfig))
            {
                // todo - how to disable it saying it here?
                var speechSynthesisResult = await speechSynthesizer.SpeakTextAsync(inp);
                return Convert.ToBase64String(speechSynthesisResult.AudioData);
            }
  • What you can do is add an audioconfig to the speechSynthesizer .您可以做的是将audioconfig添加到speechSynthesizer

  • In this audioconfig object you can specify a file path to a .wav file which already exist on the server.在此audioconfig对象中,您可以指定服务器上已存在的.wav文件的文件路径。

  • Whenever you run speaktextasyn instead of a speaker it will redirect the data to the.wav file.每当您运行speaktextasyn而不是扬声器时,它会将数据重定向到 .wav 文件。

  • This audio file you can read and perform your logic later.您可以稍后阅读此音频文件并执行您的逻辑。

  • Just add the following code before creating the speechSynthesizer object.只需在创建speechSynthesizer对象之前添加以下代码。

 var audioconfig = AudioConfig.FromWavFileOutput(filepath);

here filepath is a location of the .wav file as a string.这里的文件filepath.wav文件的位置,作为字符串。

Complete code:完整代码:

string filepath = "<file path> " ; 
var speechConfig = SpeechConfig.FromSubscription(speechKey, speechRegion); 
var audioconfig = AudioConfig.FromWavFileOutput(filepath);


            speechConfig.SpeechSynthesisVoiceName = "fa-IR-FaridNeural";
            speechConfig.OutputFormat = OutputFormat.Detailed;

            using (var speechSynthesizer = new SpeechSynthesizer(speechConfig, audioconfig))
            {
                // todo - how to disable it saying it here?
                var speechSynthesisResult = await speechSynthesizer.SpeakTextAsync(inp);
                return Convert.ToBase64String(speechSynthesisResult.AudioData);
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 认知服务语音转文本 - Azure Cognitive Services Speech to Text 使用 Azure 认知服务文本翻译 API 的 Web 应用示例 - Examples of Web App using Azure Cognitive Services Translator Text API Azure 认知服务 - 文本转语音 - SpeakTextAsync 不返回 - Azure Cognitive Services - Text-to-Speech - SpeakTextAsync does not return azure 认知服务语音到文本 webhook 回调 IP 到白名单是什么? - What is the azure cognitive services speech to text webhook callback IPs to whitelist? Xamarin表格和Azure认知服务:文字服务语音不起作用 - Xamarin forms & Azure cognitive services : Speech to text service does not work 如何从 azure 认知服务中保存转换后的文本数据? - How to save converted text data from azure cognitive services? 两个人通过 microfone 将语音转录为文本(语音到文本 azure 认知服务) - Trancription speech to text for two persons over the microfone (speech to text azure cognitive services) Azure认知语音服务的数据隐私 - Privacy of data for Azure Cognitive Speech Services Azure认知服务-使用python和websockets的自定义语音 - Azure Cognitive Services - Custom Speech with python and websockets 可以在Azure认知服务的AudioConfig功能中设置音频文件 - Out to set audio file in AudioConfig function from Azure cognitive services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM