Пример #1
0
    void OnGUI()
    {
        //If there is a microphone
        if (micConnected)
        {
            //If the audio from any microphone isn't being captured
            if (!Microphone.IsRecording(null))
            {
                //Case the 'Record' button gets pressed
                if (GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 25, 200, 50), "Record"))
                {
                    //Start recording and store the audio captured from the microphone at the AudioClip in the AudioSource
                    goAudioSource.clip = Microphone.Start(null, true, 20, maxFreq);
                }
            }
            else //Recording is in progress
            {
                //Case the 'Stop and Play' button gets pressed
                if (GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 25, 200, 50), "Stop and Play!"))
                {
                    Microphone.End(null); //Stop the audio recording
                    goAudioSource.Play(); //Playback the recorded audio
                    SaveAudio.SaveAudioClipToWav(null, "myVoice.wav");
                }

                GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 + 25, 200, 50), "Recording in progress...");
            }
        }
        else // No microphone
        {
            //Print a red "Microphone not connected!" message at the center of the screen
            GUI.contentColor = Color.red;
            GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 25, 200, 50), "Microphone not connected!");
        }
    }
Пример #2
0
    public void OnUploadBtnClick(StringVariable eventId)
    {
        string tempLabel        = "Custom";
        string serverCategory   = tempLabel;
        string soundCustomLabel = "";

        OnSoundLabelOptionChange(soundLabelDropDown);

        if (audioClip != null)
        {
            if (isCustomSoundLabel)
            {
                if (customSoundLabelText == "")
                {
                    tempLabel = randomFileNameNumber.Value.ToString();
                    randomFileNameNumber.Value++;
                }
                else
                {
                    tempLabel        = customSoundLabelText;
                    soundCustomLabel = tempLabel;
                }
            }
            else
            {
                if (soundLabelText == "")
                {
                    tempLabel = randomFileNameNumber.Value.ToString();
                    randomFileNameNumber.Value++;
                }
                else
                {
                    serverCategory = soundLabelText;
                    tempLabel      = soundLabelText + soundLabelNumbers.Value[soundLabelIndex]++;
                    //randomFileNameNumber.Value++;
                }
            }

            string saveLabel = username.text + "_" + gamePieces.Value[chosenGamePieceIndex.Value] + "_" + tempLabel;
            recordedAudioData = SaveAudio.Save(saveLabel, audioClip, fileType.Value);
            int countTemp;

            tempLabel = tempLabel + "." + fileType.Value;
            int indexInFile = CheckIfInList(tempLabel);

            if (indexInFile == -1)
            {
                Debug.Log("df");
                soundItemsFilenames.Value.Add(tempLabel);
                audioLengthFile.Value.Add(recordingTimerText.text);

                if (PlayerPrefs.GetInt("NumberOfAudioFiles") >= 0)
                {
                    countTemp = PlayerPrefs.GetInt("NumberOfAudioFiles");
                    PlayerPrefs.SetInt("NumberOfAudioFiles", countTemp + 1);
                }
                else
                {
                    countTemp = 1;
                    PlayerPrefs.SetInt("NumberOfAudioFiles", countTemp);
                }
            }
            else
            {
                countTemp          = indexInFile;
                updatedIndex.Value = indexInFile;
                audioLengthFile.Value[indexInFile] = recordingTimerText.text;
            }

            PlayerPrefs.SetString(countTemp.ToString(), tempLabel);
            PlayerPrefs.SetString("Length_" + countTemp.ToString(), recordingTimerText.text);

            StartCoroutine(UploadAudioToServer(serverCategory, soundCustomLabel, eventId.Value));

            soundLabelText = "";
        }
    }