[英]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.