Esempio n. 1
0
    private void OnRecognize(SpeechRecognitionEvent result)
    {
        if (result != null && result.results.Length > 0)
        {
            foreach (var res in result.results)
            {
                foreach (var alt in res.alternatives)
                {
                    string text;
                    if (res.final)
                    {
                        text = "Final: " + alt.transcript;
                        m_mostRecentTranscript = alt.transcript;
                        m_mostRecentFilename   = "temp/" + Webserver.GenerateFileName(netId.ToString());
                        StartCoroutine(handleUpload());
                    }
                    else
                    {
                        text = "Interim: " + alt.transcript;
                    }
                    Log.Debug("ExampleStreaming", string.Format("{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence));
                }
            }
        }
        else
        {
            // Only for debugging
//			string text = "Test";
//			m_mostRecentTranscript = text;
//			m_mostRecentFilename = Path.Combine("temp", Webserver.GenerateFileName (netId.ToString ()));
//			StartCoroutine (handleUpload ());
        }
    }
Esempio n. 2
0
    private IEnumerator RecordingHandler()
    {
        m_recordingDone = false;
        m_Recording     = Microphone.Start(m_MicrophoneID, false, m_RecordingBufferSize, m_RecordingHZ);
        yield return(null);

        if (m_Recording == null)
        {
            yield break;
        }

        while (m_Recording != null)
        {
            int writePos = Microphone.GetPosition(m_MicrophoneID);
            if (writePos > m_Recording.samples || !Microphone.IsRecording(m_MicrophoneID))
            {
                StopRecording();
            }
            if (m_recordingDone)
            {
                float[] samples = null;
                samples = new float[writePos];

                Microphone.End(m_MicrophoneID);

                m_Recording.GetData(samples, 0);

                m_mostRecentClip = AudioClip.Create("clipy", writePos, 1, m_RecordingHZ, false);
                m_mostRecentClip.SetData(samples, 0);

                string filename = Path.Combine("temp", Webserver.GenerateFileName(IAAPlayer.playerObject.GetComponent <NetworkIdentity>().netId.ToString()));
                DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
                yield return(StartCoroutine(Webserver.singleton.Upload(filename, m_mostRecentClip, handler)));

                //yield return new WaitUntil(() => handler.isDone == true);

                // create a new sound object
                IAAPlayer.playerObject.GetComponent <MakeSoundObject>().CmdSpawnSoundObject("", 1f, Vector3.one, Quaternion.identity, filename, true);
                yield break;
            }
            else
            {
                yield return(new WaitUntil(() => m_recordingDone == true));
            }
        }

        yield break;
    }