- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Watson 的 Speech-To-Text Unity SDK
中指定关键字,但我不确定如何执行此操作。
详细信息页面没有显示示例(参见此处:https://www.ibm.com/watson/developercloud/doc/speech-to-text/output.shtml),
和其他论坛帖子是为 Java 应用程序编写的(参见此处:How to specify phonetic keywords for IBM Watson speech2text service?)。
我试过像这样在“识别”函数中创建的 RecognizeRequest
类中对这些值进行硬编码,但没有成功:
**编辑——这个函数永远不会被调用——**
public bool Recognize(AudioClip clip, OnRecognize callback)
{
if (clip == null)
throw new ArgumentNullException("clip");
if (callback == null)
throw new ArgumentNullException("callback");
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/recognize");
if (connector == null)
return false;
RecognizeRequest req = new RecognizeRequest();
req.Clip = clip;
req.Callback = callback;
req.Headers["Content-Type"] = "audio/wav";
req.Send = WaveFile.CreateWAV(clip);
if (req.Send.Length > MAX_RECOGNIZE_CLIP_SIZE)
{
Log.Error("SpeechToText", "AudioClip is too large for Recognize().");
return false;
}
req.Parameters["model"] = m_RecognizeModel;
req.Parameters["continuous"] = "false";
req.Parameters["max_alternatives"] = m_MaxAlternatives.ToString();
req.Parameters["timestamps"] = m_Timestamps ? "true" : "false";
req.Parameters["word_confidence"] = m_WordConfidence ? "true" :false";
//these "keywords" and "keywords_threshold" and "keywordsThreshold" parameters
//are just my guess for how to set these values
req.Parameters["keywords"] = new string[] {"fun", "match", "test" };
req.Parameters["keywordsThreshold"] = .2;
req.Parameters["keywords_threshold"] = .2;
//end my test insertions
req.OnResponse = OnRecognizeResponse;
return connector.Send(req);
}
但返回的 SpeechRecognitionEvent
结果值不包含任何 keywords_result
。这是我的目标。我试图像这样查看 keywords_result 对象中每个关键字的置信度,但 keywords_result
对象返回为 null
。
private void OnRecognize(SpeechRecognitionEvent result) {
Debug.Log("Recognizing!");
m_ResultOutput.SendData(new SpeechToTextData(result));
if (result != null && result.results.Length > 0) {
if (m_Transcript != null)
m_Transcript.text = "";
foreach (var res in result.results) {
//the res.keywords_result comes back as null
foreach (var keyword in res.keywords_result.keyword) {
string text = keyword.normalized_text;
float confidence = keyword.confidence;
Debug.Log(text + ": " + confidence);
}
}
}
}
有没有人在 Unity 或 C# 中使用 Watson 的 Speech-To-Text SDK 成功实现了关键字置信度评估?欢迎所有想法和建议。
PS 这是我的第一篇文章:)
最佳答案
原来我需要像这样在“SendStart”函数中指定关键字:
private void SendStart() {
if (m_ListenSocket == null)
throw new WatsonException("SendStart() called with null connector.");
Dictionary<string, object> start = new Dictionary<string, object>();
start["action"] = "start";
start["content-type"] = "audio/l16;rate=" + m_RecordingHZ.ToString() + ";channels=1;";
start["continuous"] = EnableContinousRecognition;
start["max_alternatives"] = m_MaxAlternatives;
start["interim_results"] = EnableInterimResults;
start["word_confidence"] = m_WordConfidence;
start["timestamps"] = m_Timestamps;
//specify keywords here
start["keywords"] = keywordsToCheck.ToArray();
start["keywords_threshold"] = 0.05;
//end additions here
m_ListenSocket.Send(new WSConnector.TextMessage(Json.Serialize(start)));
m_LastStartSent = DateTime.Now;
}
并在“ParseRecognizeResponse”函数中编写一些代码来正确解析 keyword_results:
private SpeechRecognitionEvent ParseRecognizeResponse(IDictionary resp){
if (resp == null)
return null;
List<SpeechRecognitionResult> results = new List<SpeechRecognitionResult>();
IList iresults = resp["results"] as IList;
if (iresults == null)
return null;
foreach (var r in iresults)
{
IDictionary iresult = r as IDictionary;
if (iresults == null)
continue;
SpeechRecognitionResult result = new SpeechRecognitionResult();
//added this section, starting here
IDictionary iKeywords_result = iresult["keywords_result"] as IDictionary;
result.keywords_result = new KeywordResults();
List<KeywordResult> keywordResults = new List<KeywordResult>();
foreach (string key in keywordsToCheck) {
if (iKeywords_result[key] != null) {
IList keyword_Results = iKeywords_result[key] as IList;
if (keyword_Results == null) {
continue;
}
foreach (var res in keyword_Results) {
IDictionary kw_resultDic = res as IDictionary;
KeywordResult keyword_Result = new KeywordResult();
keyword_Result.confidence = (double)kw_resultDic["confidence"];
keyword_Result.end_time = (double)kw_resultDic["end_time"];
keyword_Result.start_time = (double)kw_resultDic["start_time"];
keyword_Result.normalized_text = (string)kw_resultDic["normalized_text"];
keywordResults.Add(keyword_Result);
}
}
}
result.keywords_result.keyword = keywordResults.ToArray();
//ends here
result.final = (bool)iresult["final"];
IList ialternatives = iresult["alternatives"] as IList;
if (ialternatives == null)
continue;
List<SpeechRecognitionAlternative> alternatives = new List<SpeechRecognitionAlternative>();
foreach (var a in ialternatives)
{
IDictionary ialternative = a as IDictionary;
if (ialternative == null)
continue;
SpeechRecognitionAlternative alternative = new SpeechRecognitionAlternative();
alternative.transcript = (string)ialternative["transcript"];
if (ialternative.Contains("confidence"))
alternative.confidence = (double)ialternative["confidence"];
if (ialternative.Contains("timestamps"))
{
IList itimestamps = ialternative["timestamps"] as IList;
TimeStamp[] timestamps = new TimeStamp[itimestamps.Count];
for (int i = 0; i < itimestamps.Count; ++i)
{
IList itimestamp = itimestamps[i] as IList;
if (itimestamp == null)
continue;
TimeStamp ts = new TimeStamp();
ts.Word = (string)itimestamp[0];
ts.Start = (double)itimestamp[1];
ts.End = (double)itimestamp[2];
timestamps[i] = ts;
}
alternative.Timestamps = timestamps;
}
if (ialternative.Contains("word_confidence"))
{
IList iconfidence = ialternative["word_confidence"] as IList;
WordConfidence[] confidence = new WordConfidence[iconfidence.Count];
for (int i = 0; i < iconfidence.Count; ++i)
{
IList iwordconf = iconfidence[i] as IList;
if (iwordconf == null)
continue;
WordConfidence wc = new WordConfidence();
wc.Word = (string)iwordconf[0];
wc.Confidence = (double)iwordconf[1];
confidence[i] = wc;
}
alternative.WordConfidence = confidence;
}
alternatives.Add(alternative);
}
result.alternatives = alternatives.ToArray();
results.Add(result);
}
return new SpeechRecognitionEvent(results.ToArray());
}
现在,当 OnRecognize 通过此 SpeechRecognitionEvent 时,我更改了显示备选词及其置信度分数的代码,以显示关键字结果及其置信度分数,如下所示:
private void OnRecognize(SpeechRecognitionEvent result) {
//Debug.Log("Recognizing!");
m_ResultOutput.SendData(new SpeechToTextData(result));
if (result != null && result.results.Length > 0) {
if (m_Transcript != null)
m_Transcript.text = "";
foreach (var res in result.results) {
//start keyword recognition changes here
if (res.keywords_result != null) {
if (res.keywords_result.keyword != null) {
foreach (var keyword in res.keywords_result.keyword) {
m_Transcript.text += string.Format("{0} ({1}, {2:0.00})\n",
keyword.normalized_text, res.final ? "Final" : "Interim", keyword.confidence);
}
}
}
//end here
}
}
}
请注意,使用关键字结果置信度值比进行一些硬编码检查以查看 Watson 正在获取的备选词是否与您的关键字匹配,然后在那里使用置信度值更有值(value)。检查 keyword_results.keyword[].confidence 值时,置信度值会高得多,因为它已经在检查这些词。这是完成此过程并解析 SpeechRecognitionEvent 结果值以正确包含 keywords_result 值的动力。
在某些背景下,我正在为有阅读障碍的 child 制作一个节奏游戏来学习构词,所以想想《吉他英雄》遇见芝麻街吧。
关于c# - 对于 Watson 的 Speech-To-Text Unity SDK,您如何指定关键字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39940174/
我只是尝试使用 Microsoft.Speech.dll; 为文本转语音运行简单的 Microsoft 示例 using System; using Microsoft.Speech.Synthesi
微软似乎提供了不少语音识别产品,我想知道它们之间的区别。 有Microsoft Speech API ,或 SAPI。但不知何故Microsoft Cognitive Service Speech A
我希望编写一个应用程序,将语音到文本转换为仓库应用程序,反之亦然。主要用例是运算符(operator)将在仓库中佩戴耳机并将指令发送回服务器并从仓库软件接收指令以拣选和打包订单。我们将使用由 Wind
我正在探索 python 中的谷歌云语音 api。我正在关注这个 link .我也提到了这个 stackoverflow link .但是我对设置环境变量感到震惊。 我做过的事情: 1.安装gclou
在尝试让 Speech to Text(IBM 语音网关 IVR 应用程序)识别字母数字字符串时,我想知道我是否可以创建一个自定义语法或实体来限制 STT 仅识别单个字母和数字,不包括完全的话。例如,
是否可以将来自Web Speech API的合成语音用作Web Audio API音频上下文中的SourceNode? 最佳答案 实际上,我问过要在Web Speech邮件列表中添加此内容,并且基本上
使用 Microsoft Speech API 转录中/大型音频文件(每个文件约 6-10 分钟)的最佳方法是什么?像批处理音频文件转录这样的东西? 我使用了 https://docs.microso
我的 .wav 文件长度只有 4 秒。即使在多次重试并在云端运行后,我仍然不断收到以下错误 * upload completely sent off: 12 out of 12 bytes
我找到了一些描述如何使用 Google 语音 API 的文章 ( http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
我使用 google 语音转文本 API 从音频中获取字幕,但是当音频太长时,通常超过 60 分钟,重试次数过多会失败。它说:google.api_core.exceptions.GoogleAPIC
我有一些来自 System.Speech.Recognition 的简单代码可以正常工作: using (var recognizer = new SpeechRecognitionEngine(ne
Windows 10。我在“设置”中安装了日语 TTS 语音。现在,当我在 Speech API 5.4 OneCore 中使用语音枚举时(虽然不是在 5.4 中),我得到 6 个语音: 大卫 齐拉
当我提交对太长文本的综合请求时,我收到以下错误: google.api_core.exceptions.ResourceExhausted: 429 Received message larger t
我是 C# 的新手,也是 Speech.Recognition 的新手。我搜索了很长时间的教程,但没有找到那么多,我什至不确定我是否正确包含了所有内容。 我下载了: SDK Runtime Langu
我有一个奇怪的要求,即在我现有的应用程序中我有 Text2Speech 并且为此,我使用了 AVSpeechSynthesizer 来语音文本,但现在要求改变了,现在我需要将 HTML 文件数据转换为
我使用 Google Speech API 通过 Python 识别 .OGG 文件音频中的越南语语音。但它不会返回任何结果。 最佳答案 至少在英文版的Google Speech API中,需要使用F
我想从手机录制音频,然后将其发送到谷歌语音非流媒体 API。我可以使用 Capture.captureAudio() 进行录音,但是我不知道音频编码和采样率是什么,因为它们是必需的 for the a
我使用谷歌云语音到文本 API 将音频转换为文本。 对于 .raw文件它工作正常 但是对于 .wav文件它给了我类似的错误: Google::Gax::RetryError Exception: Ga
.NET 中有两个类似的用于语音识别的命名空间和程序集。我试图了解其中的差异以及何时适合使用其中之一。 程序集 System.Speech(在 System.Speech.dll 中)有 System
通过流式 API (Performing Streaming Speech Recognition on an Audio Stream) 使用 Google Cloud Speech API, 我们
我是一名优秀的程序员,十分优秀!