IEnumerator Record() { character_pages.initValue(); if (blame.guilt == killerName) { character_pages.appendValue(killerName); //We are setting a male voice to this response request_info.setResponseAudioVoice("Richard"); } //In this conditional we will hit only the page corresponding to the character "Anna", //that will respond "No, I didn't kill that guy" to the "Did you kill that guy" question else { character_pages.appendValue(innocentName); //We are setting a female voice to this response request_info.setResponseAudioVoice("Sarah"); } m_clip = Microphone.Start(Microphone.devices[0], true, 1000, 16000); lastPos = 0; // Create a HoundRequester.VoiceRequest object lph.bt = this; request = requester.start_voice_request(null, request_info, lph); sending = true; stopRecording = false; while (Microphone.IsRecording(Microphone.devices[0])) { yield return(null); } sending = false; hound_result = request.finish(); Debug.Log("stopped!"); //StringWriter txt = new StringWriter(); //JSONStreamWriter h = new JSONStreamWriter(txt); //hound_result.write_as_json(h); //Debug.Log(txt.GetStringBuilder().ToString()); ////play the clip back if (hound_result.getAllResults().Count > 0) { wav = new WAV(System.Convert.FromBase64String(hound_result.getAllResults()[0].getResponseAudioBytes())); audioClip = AudioClip.Create("testSound", wav.SampleCount, 1, wav.Frequency, false, false); audioClip.SetData(wav.LeftChannel, 0); audioSource.clip = audioClip; audioSource.Play(); } else { Debug.Log("NO RESULT - ERROR FROM HOUNDIFY"); } }
public static int sample_hound_driver(HoundRequester requester) { string session_id = Guid.NewGuid().ToString(); ConversationStateJSON conversation_state = null; while (true) { string line = Console.ReadLine(); if (line == null) { return(0); } RequestInfoJSON request_info = new RequestInfoJSON(); request_info.setUnitPreference( RequestInfoJSON.TypeUnitPreference.UnitPreference_US); request_info.setRequestID(Guid.NewGuid().ToString()); request_info.setSessionID(session_id); RequestInfoJSON.TypeClientVersion client_version = new RequestInfoJSON.TypeClientVersion(); client_version.key = 0; client_version.choice0 = "1.0"; request_info.setClientVersion(client_version); HoundServerJSON hound_result; if ((line.StartsWith("-audio ")) || (line.StartsWith("-transcript-audio ")) || (line.StartsWith("-slow-transcript-audio "))) { bool go_slowly = line.StartsWith("-slow-transcript-audio "); bool show_transcript = (line.StartsWith("-transcript-audio ") || line.StartsWith("-slow-transcript-audio ")); LocalPartialHandler partial_handler = new LocalPartialHandler(show_transcript); HoundRequester.VoiceRequest request = requester.start_voice_request(conversation_state, request_info, partial_handler); int file_name_position = 0; while (line[file_name_position] != ' ') { ++file_name_position; } ++file_name_position; String file_name = line.Substring(file_name_position); BinaryReader audio_stream; try { audio_stream = new BinaryReader( File.Open(file_name, FileMode.Open)); } catch (Exception e1) { Console.Error.Write( "Error trying to open audio file `{0}': {1}\n", file_name, e1.Message); return(1); } while (true) { byte[] buffer = new byte[2052]; int byte_count = audio_stream.Read(buffer, 0, 2052); if (byte_count > 0) { request.add_audio(byte_count, buffer); } if (byte_count < 2052) { break; } if (go_slowly) { Thread.Sleep(500); } } audio_stream.Close(); hound_result = request.finish(); } else { hound_result = requester.do_text_request(line, conversation_state, request_info); } if (hound_result == null) { return(1); } if (hound_result.hasAllResults()) { if (hound_result.countOfAllResults() == 0) { Console.Write("No match.\n"); conversation_state = null; } else { CommandResultJSON command = hound_result.elementOfAllResults(0); Console.Write("Result"); if (hound_result.hasLocalOrRemote()) { Console.Write(" [{0}]", ((hound_result.getLocalOrRemote() == HoundServerJSON.TypeLocalOrRemote. LocalOrRemote_Local) ? "Local" : "Remote")); } Console.Write(": {0}\n", command.getWrittenResponseLong()); if (command.hasConversationState()) { conversation_state = command.getConversationState(); } else { conversation_state = null; } } } else if (hound_result.hasErrorMessage()) { Console.Write("Error from server: {0}\n", hound_result.getErrorMessage()); conversation_state = null; } else { Console.Write("No result or error from server.\n"); conversation_state = null; } } }