Exemplo n.º 1
0
    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");
        }
    }
    private void  fromJSONValue(JSONValue json_value, bool ignore_extras)
    {
        Debug.Assert(json_value != null);
        TypeValue or_result = new TypeValue();
        bool      or_done   = false;

        if (!or_done)
        {
            try
            {
                HoundServerJSON convert_classy = HoundServerJSON.from_json(json_value, ignore_extras, true);
                or_result.u.choice0 = convert_classy;
                or_result.key       = 0;
                or_done             = true;
            }
            catch (Exception)
            {
            }
        }
        if (!or_done)
        {
            try
            {
                HoundPartialTranscriptJSON convert_classy = HoundPartialTranscriptJSON.from_json(json_value, ignore_extras, true);
                or_result.u.choice1 = convert_classy;
                or_result.key       = 1;
                or_done             = true;
            }
            catch (Exception)
            {
            }
        }
        if (!or_done)
        {
            try
            {
                HoundUpdateJSON convert_classy = HoundUpdateJSON.from_json(json_value, ignore_extras, true);
                or_result.u.choice2 = convert_classy;
                or_result.key       = 2;
                or_done             = true;
            }
            catch (Exception)
            {
            }
        }
        if (!or_done)
        {
            throw new Exception("The value for field Value of HoundMessageJSON is not one of the allowed values.");
        }
        setValue(or_result);
        switch (or_result.key)
        {
        case 0:
            break;

        case 1:
            break;

        case 2:
            break;

        default:
            Debug.Assert(false);
            break;
        }
    }