[英]Azure Text to Speech (Cognitive Services) in web app - how to stop it from outputting audio?
我在 Web 應用中使用 Azure 文本轉語音認知服務。
我將字節返回給瀏覽器並且效果很好,但是在服務器(或本地計算機)上, speechSynthesizer.SpeakTextAsync(inp)行將音頻輸出到揚聲器。
有沒有辦法關閉它,因為它在網絡服務器上運行(即使我忽略它,它在發送回數據之前輸出音頻時也會有延遲)
這是我的代碼...
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);
}
您可以做的是將audioconfig
添加到speechSynthesizer
。
在此audioconfig
對象中,您可以指定服務器上已存在的.wav
文件的文件路徑。
每當您運行speaktextasyn
而不是揚聲器時,它會將數據重定向到 .wav 文件。
您可以稍后閱讀此音頻文件並執行您的邏輯。
只需在創建speechSynthesizer
對象之前添加以下代碼。
var audioconfig = AudioConfig.FromWavFileOutput(filepath);
這里的文件filepath
是.wav
文件的位置,作為字符串。
完整代碼:
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.