gpt4 book ai didi

c# - 如何将连续的语音转文本服务(使用 MS 认知服务)包含到写入页面文本框的 ASP.NET Web 应用程序中?

转载 作者:行者123 更新时间:2023-12-04 10:52:01 25 4
gpt4 key购买 nike

我正在尝试在 ASP.net 应用程序中包含连续的语音到文本服务。用户在客户端使用麦克风,语音在文本框中被捕获。服务器端将使用 Microsoft 在 Azure 上的 Cognitive 服务。我找到了这篇文章 https://codez.deedx.cz/posts/continuous-speech-to-text/ .我不确定客户端将如何与此 API 对话。捕获客户端和服务器端的任何帮助或示例代码将不胜感激。

谢谢!

最佳答案

如果您想将 Speech to text(stt) 服务与您的 asp.net 应用程序集成,也许使用 stt 服务作为 HTML 页面并将其作为 View 集成将是最简单的方法。

我为你写了一个连续的语音文本HTML演示,试试下面的代码:

<!DOCTYPE html>
<html>
<head>
<title>Microsoft Cognitive Services Speech SDK JavaScript Quickstart</title>
<meta charset="utf-8" />
</head>
<body style="font-family:'Helvetica Neue',Helvetica,Arial,sans-serif; font-size:13px;">
<!-- <uidiv> -->

<div id="content" style="display:none">
<table width="100%">
<tr>
<td></td>
<td><h1 style="font-weight:500;">Continuous speech to text demo </h1></td>
</tr>
<td></td>
<td><button id="startRecognizeAsyncButton">Start recognition</button>
<button id="stopRecognizeAsyncButton">Stop recognition</button>
</td>

</tr>
<tr>
<td align="right" valign="top">Results</td>
<td><textarea id="phraseDiv" style="display: inline-block;width:500px;height:200px"></textarea></td>
</tr>
</table>
</div>

<script src="microsoft.cognitiveservices.speech.sdk.bundle.js"></script>

<script>
// status fields and start button in UI
var subscriptionKey = "<your subscription key>";
var serviceRegion= "<your region>";
var phraseDiv;
var startRecognizeAsyncButton;
var stopRecognizeAsyncButton;
var SpeechSDK;
var recognizer;
document.addEventListener("DOMContentLoaded", function () {
startRecognizeAsyncButton = document.getElementById("startRecognizeAsyncButton");
stopRecognizeAsyncButton = document.getElementById("stopRecognizeAsyncButton");
stopRecognizeAsyncButton.disabled=true;
phraseDiv = document.getElementById("phraseDiv");
var speechConfig;
speechConfig = SpeechSDK.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);
speechConfig.speechRecognitionLanguage = "en-US";
var audioConfig = SpeechSDK.AudioConfig.fromDefaultMicrophoneInput();
recognizer = new SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);

startRecognizeAsyncButton.addEventListener("click", function () {
startRecognizeAsyncButton.disabled = true;
stopRecognizeAsyncButton.disabled=false;
phraseDiv.innerHTML = "";

recognizer.startContinuousRecognitionAsync();
recognizer.recognized = function(s, e){
phraseDiv.innerHTML += e.result.text;
};
});

stopRecognizeAsyncButton.addEventListener("click",function(){
startRecognizeAsyncButton.disabled = false ;
stopRecognizeAsyncButton.disabled = true ;
recognizer.stopContinuousRecognitionAsync();

});
if (!!window.SpeechSDK) {
SpeechSDK = window.SpeechSDK;
startRecognizeAsyncButton.disabled = false;
document.getElementById('content').style.display = 'block';
document.getElementById('warning').style.display = 'none';
// in case we have a function for getting an authorization token, call it.
if (typeof RequestAuthorizationToken === "function") {
RequestAuthorizationToken();
}
}
});
</script>
<!-- </quickstartcode> -->
</body>
</html>

如何运行它:

  1. 将代码保存为 .html 文件。
  2. subscriptionKeyserviceRegion 替换为您自己的服务值,您可以在这里找到它们:

enter image description here

3.来自Speech SDK for JavaScript .zip package提取文件 microsoft.cognitiveservices.speech.sdk.bundle.js 并将其放入包含此示例的文件夹中。如下所示: enter image description here

测试结果:

enter image description here

希望对您有所帮助!

关于c# - 如何将连续的语音转文本服务(使用 MS 认知服务)包含到写入页面文本框的 ASP.NET Web 应用程序中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59435588/

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