Beispiel #1
0
    private IEnumerator DecodeSpeech(byte[] wavSpeech)
    {
        var speechRequest = new JObject(
            new JProperty("audio", new JObject(
                new JProperty("content", Convert.ToBase64String(wavSpeech))
            )),
            new JProperty("config", new JObject(
                new JProperty("languageCode", new JValue("fi"))
            ))
        );

        var content = speechRequest.ToString();

        using (WWW www = doPost("https://speech.googleapis.com/v1/speech:recognize", content))
        {
            yield return www;

            var speechResponse = JObject.Parse(www.text);
            var results = (JArray)speechResponse["results"];
            if (results != null && results.Count > 0)
            {
                string val = (string)results[0]["alternatives"][0]["transcript"];
                onSpeechRecognized.Invoke(val);
            }
        }
    }
 /// <summary>
 /// 音声認識完了イベントを発生
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnSpeechRecognizedEvent(SpeechRecognizedEventArgs e)
 {
     SpeechRecognizedEvent?.Invoke(this, e);
 }