2016-10-09 12 views
3

私はWatsonのSpeech-To-Text Unity SDKでキーワードを指定しようとしていますが、これを行う方法がわかりません。 、WatsonのSpeech-To-Text Unity SDKでは、どのようにキーワードを指定できますか?

をし、他のフォーラムの投稿は、(ここを参照してください:How to specify phonetic keywords for IBM Watson speech2text service?)をJavaアプリケーションのために書かれています。

詳細ページには例を示していない(https://www.ibm.com/watson/developercloud/doc/speech-to-text/output.shtmlをここを参照してください)。

私は成功せず、そのような関数を「認識」で作成し RecognizeRequestクラスでこれらの値をハードコーディング試してみた

** EDIT - この関数が呼び出されることは決してありません - **

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これは私の最初の投稿です:)

+0

これはWatsonで行う必要がありますか?そうでなければ[ここ](http://stackoverflow.com/a/39613264/3785314)を見てください。 – Programmer

+0

私はあなたが低いしきい値を試してみる必要があると思います。 0.2または0.00001の代わりに0.1を試してください。 –

+0

UnityのSpeech-To-TextはWatsonを使用して作業します。ここのコメント欄を参照してください。 https://www.assetstore.unity3d.com/en/#!/content/69399 –

答えて

3

は、私はそうのように「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; 
    } 

とで正しくkeyword_resultsを解析するためにいくつかのコードを書きます「ParseRecognizeResponse」機能:OnRecognizeこのSpeechRecognitionEventを渡されるとき

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());       
    } 

だから今、私は言葉の代わりを表示するためのコードを変更しましたsであり、その信頼性スコアは、キーワードの結果とその信頼性スコアを表示するには、そのよう:

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     
     } 
    } 
} 

注意、キーワードの結果の信頼値を使用すると、単語選択肢ワトソンがあるかどうかを確認するために、いくつかのハードコードされたチェックを行うよりもはるかに価値がありますあなたのキーワードにマッチさせ、そこに信頼値を使用します。 keyword_results.keyword []。confidence値をチェックすると、信頼値はすでにそれらの単語に対してチェックしているので、かなり高い値に戻ります。これは、このプロセスを通過し、SpeechRecognitionEvent結果値を解析して、keywords_result値を適切に含めるための刺激となりました。

バックグラウンドでは、単語形成を学ぶためにディスレクシアの子供のためのリズムゲームを作成していますので、ギターヒーローがセサミストリートに会うと思います。

関連する問題