public void GetText(AudioClip audio)
    {
        if (UploadStarted != null)
        {
            UploadStarted();
        }

        float filenameRand = UnityEngine.Random.Range(0.0f, 10.0f);

        string filename = "testing" + filenameRand;

        //Debug.Log("Recording Stopped");

        if (!filename.ToLower().EndsWith(".wav"))
        {
            filename += ".wav";
        }

        var filePath = Path.Combine("testing/", filename);

        filePath = Path.Combine(Application.persistentDataPath, filePath);
        //Debug.Log("Created filepath string: " + filePath);

        // Make sure directory exists if user is saving to sub dir.
        Directory.CreateDirectory(Path.GetDirectoryName(filePath));
        SaveWav.Save(filePath, audio); //Save a temporary Wav File
        //Debug.Log("Saving @ " + filePath);
        //Insert your API KEY here.
        string apiURL = "https://speech.googleapis.com/v1/speech:recognize?&key=" + apiKey;
        string Response;

        //Debug.Log("Uploading " + filePath);
        Response = HttpUploadFile(apiURL, filePath, "file", "audio/wav; rate=44100");
        //Debug.Log(Response);

        GoogleCloudResponse parsedResponse = JsonUtility.FromJson <GoogleCloudResponse>(Response);

        //Debug.Log(parsedResponse);
        try
        {
            if (ResponseRecieved != null)
            {
                ResponseRecieved(parsedResponse);
            }
        }
        catch (NullReferenceException e) {}

        //goAudioSource.Play(); //Playback the recorded audio

        File.Delete(filePath); //Delete the Temporary Wav file
    }
Exemplo n.º 2
0
 private void ResponseRecieved(GoogleCloudResponse response)
 {
     //Debug.Log(response.results[0].alternatives[0].transcript);
     //text.text = response.results[0].alternatives[0].transcript;
     if (shopType == thisShop && taskItem == response.results[0].alternatives[0].transcript)
     {
         //Debug.Log("true" + thisShop + response.results[0].alternatives[0].transcript);
         TaskManager.evaluateFromVoice(true);
     }
     else
     {
         //Debug.Log("false" + thisShop + response.results[0].alternatives[0].transcript);
         TaskManager.evaluateFromVoice(false);
     }
 }
 private void ResponseRecieved(GoogleCloudResponse response)
 {
     //Debug.Log(response.results[0].alternatives[0].transcript);
     //text.text = response.results[0].alternatives[0].transcript;
 }