##聞きたいこと
下記記載のコードに対してnot all code paths return a value
とのエラーが出ています。
どうやら、「全てのコードが戻り値を返すようになってない」という意味らしいのですが、どこを改善していいか分からず。。。
どなたか対応方法わかりますでしょうか...??
(C#もUnityも初心者で丸投げの質問になってたらすみません...!情報の過不足などあればご指摘ください!)
##実現したいこと
UnityとWatsonを使って、「おはよう」と話しかけたら「おはよう」と音声で返してくれるようなものを作ろうとしてます。
スタートから4秒間マイクで集音し、WatsonのSpeachToTextで日本語文字列に変換→「おはよう」の文字列が入っていれば、TextToSeachで「おはよう」と音声で返す、といったものです。
##コード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using IBM.Watson.DeveloperCloud.Services.TextToSpeech.v1; 5using IBM.Watson.DeveloperCloud.Services.SpeechToText.v1; 6 7public class WatsonConversation : MonoBehaviour { 8 9 10 [SerializeField] 11 SpeechToText m_SpeechToText = new SpeechToText(); 12 TextToSpeech m_TextToSpeech = new TextToSpeech(); 13 string m_ResString = "おはよう"; 14 15 // Use this for initialization 16 IEnumerator Start() { 17 var audioSource = GetComponent<AudioSource>(); 18 RecMic(audioSource); 19 } 20 21 IEnumerator RecMic(AudioSource audioSource) { 22 // 音声をマイクから4秒間取得 23 Debug.Log ("Start record"); 24 audioSource.clip = Microphone.Start(null, true, 10, 44100); 25 audioSource.loop = false; 26 audioSource.spatialBlend = 0.0f; 27 yield return new WaitForSeconds (4f); 28 Microphone.End (null); 29 Debug.Log ("Finish record"); 30 31 // 音声の認識言語を日本語に指定 32 m_SpeechToText.RecognizeModel = "ja-JP_BroadbandModel"; 33 // 音声をテキストに変換し、関数:HandleOnRecognize()を呼ぶ 34 m_SpeechToText.Recognize(audioSource.clip, HandleOnRecognize); 35 36 } 37 38 void HandleOnRecognize(SpeechRecognitionEvent result){ 39 if (result != null && result.results.Length > 0){ 40 foreach (var res in result.results){ 41 foreach (var alt in res.alternatives){ 42 string text = alt.transcript; 43 Debug.Log(string.Format("{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence)); 44 45 //textに"おはよう"があれば、おはようと返すしてしゃべる 46 if (text.Contains("おはよう")) { 47 m_TextToSpeech.Voice = VoiceType.ja_JP_Emi; //音声タイプを指定 48 m_TextToSpeech.ToSpeech(m_ResString, HandleToSpeechCallback); 49 50 } 51 } 52 } 53 } 54 } 55 56 void HandleToSpeechCallback (AudioClip clip) { 57 PlayClip(clip); 58 } 59 60 private void PlayClip(AudioClip clip) { 61 if (Application.isPlaying && clip != null) { 62 GameObject audioObject = new GameObject("AudioObject"); 63 AudioSource source = audioObject.AddComponent<AudioSource>(); 64 source.spatialBlend = 0.0f; 65 source.loop = false; 66 source.clip = clip; 67 source.Play(); 68 69 GameObject.Destroy(audioObject, clip.length); 70 } 71 } 72 73// void Update () { 74// 75// } 76} 77
##調べたページ
https://www21.atwiki.jp/mizcremorne/pages/315.html#id_c9a4eb10

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/13 06:10
退会済みユーザー
2017/08/13 06:36
2017/08/13 07:54 編集