gpt4 book ai didi

javascript - 如何在 JavaScript 中更改 Azure 文本到语音静音超时

转载 作者:行者123 更新时间:2023-12-03 00:54:28 34 4
gpt4 key购买 nike

我正在使用 Azure SpeechSDK 服务通过 recognizeOnceAsync 进行语音到文本转录。当前代码类似于:

var SpeechSDK, recognizer, synthesizer;
var speechConfig = SpeechSDK.SpeechConfig.fromSubscription('SUB_KEY', 'SUB_REGION');
var audioConfig = SpeechSDK.AudioConfig.fromDefaultMicrophoneInput();
recognizer = new SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);
new Promise(function(resolve) {
recognizer.onend = resolve;
recognizer.recognizeOnceAsync(
function (result) {
recognizer.close();
recognizer = undefined;
resolve(result.text);
},
function (err) {
alert(err);
recognizer.close();
recognizer = undefined;
}
);
}).then(r => {
console.log(`Azure STT enterpreted: ${r}`);
});

在 HTML 文件中,我导入 Azure 包,如下所示:

<script src="https://aka.ms/csspeech/jsbrowserpackageraw"></script>

问题是我想增加 recognizeOnceAsync 方法返回结果之前允许的“静默时间”量。 (也就是说,假设您已经说完话,您应该能够停下来呼吸一下,而无需使用该方法)。有没有办法用 fromDefaultMicrophoneInput 来做到这一点?我尝试过各种方法,例如:

const SILENCE_UNTIL_TIMEOUT_MS = 5000;
speechConfig.SpeechServiceConnection_EndSilenceTimeoutMs = SILENCE_UNTIL_TIMEOUT_MS;
audioConfig.setProperty("Speech_SegmentationSilenceTimeoutMs", SILENCE_UNTIL_TIMEOUT_MS);

但似乎没有人正确延长“沉默时间津贴”。

这是我一直在查看的资源: https://learn.microsoft.com/en-us/javascript/api/microsoft-cognitiveservices-speech-sdk/propertyid?view=azure-node-latest

最佳答案

根据您所描述的内容,您需要设置分段静默超时。不幸的是,目前 JS SDK 中存在一个错误,PropertyId.Speech_SegmentationSilenceTimeoutMs 未正确设置。

作为解决方法,您可以按如下方式设置分段超时:

const speechConfig = SpeechConfig.fromSubscription(subscriptionKey, subscriptionRegion);
speechConfig.speechRecognitionLanguage = "en-US";

const reco = new SpeechRecognizer(speechConfig);
const conn = Connection.fromRecognizer(reco);
conn.setMessageProperty("speech.context", "phraseDetection", {
"INTERACTIVE": {
"segmentation": {
"mode": "custom",
"segmentationSilenceTimeoutMs": 5000
}
},
mode: "Interactive"
});

reco.recognizeOnceAsync(
(result) =>
{
console.log("Recognition done!!!");
// do something with the recognition
},
(error) =>
{
console.log("Recognition failed. Error:" + error);
});

请注意,分段超时允许的范围是 100-5000 毫秒(含)

关于javascript - 如何在 JavaScript 中更改 Azure 文本到语音静音超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73322254/

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