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")) { Microphone.End(null); //Stop the audio recording AudioClip trimmedClip = SaveWav.TrimSilence(goAudioSource.clip, 0f); SaveWav.Save(fileName, trimmedClip); } 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!"); } }
// Update is called once per frame void Update() { if (pressedButton == true) { pressedButton = false; if (isRecording) { myResultBox.text = "Listening for command"; commandClip = Microphone.Start(null, false, 5, samplerate); //Start recording (rewriting older recordings) } if (!isRecording) { myResultBox.text = null; myResultBox.text = "Saving Voice Request"; // Save the audio file Microphone.End(null); if (SaveWav.Save("sample", commandClip)) //Savewav is a static class { myResultBox.text = "Sending audio to AI..."; } else { myResultBox.text = "FAILED"; } // At this point, we can delete the existing audio clip commandClip = null; //Start a coroutine called "WaitForRequest" with that WWW variable passed in as an argument StartCoroutine(SendRequestToWitAi()); } } }
public void Validate() { // Save the audio file Microphone.End(null); SaveWav.Save("sample", commandClip); // At this point, we can delete the existing audio clip commandClip = null; //Grab the most up-to-date JSON file // url = "https://api.wit.ai/message?v=20160305&q=Put%20the%20box%20on%20the%20shelf"; token = "V65J5VZSQLT6QBHHQETEK4DYR7L7DOBK"; //Start a coroutine called "WaitForRequest" with that WWW variable passed in as an argument string witAiResponse = GetJSONText(Application.persistentDataPath + "/Sample.wav"); print(witAiResponse); var N = JSON.Parse(witAiResponse); // Find the word string speechWord = N["entities"]["word"][0]["value"].Value.ToLower(); print(speechWord); speechText.text = speechWord; if (speechText.text == ButtonClicked.CurrentVocabularyBtnClickedName.ToLower()) { //StartCoroutine(understood.comparePronunciation()); } LoadingPanel.SetActive(false); }
public void SaveAudio(AudioClip _clip, string _key) { if (_clip == null) { return; } SaveWav.Save(_key, _clip); }
private void StopRecording() { animations.Animators.LaiAnimator.SetBool("speak", false); if (micConnected && Microphone.IsRecording(null)) { Microphone.End(null); SaveWav.Save("SpellingAudio", clip); CheckForConnection(); } }
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 }
private void Start() { CreateDirectories(); trackList = Directory.GetFiles(defaultPath + musicPath, "*.mp3"); convertedList = new string[trackList.Length]; for (int i = 0; i < trackList.Length; i++) { StartCoroutine(DownloadWWW("file:///" + trackList[i])); AudioClip clip = NAudioPlayer.FromMp3Data(www.bytes, trackList[i]); string fileName = Path.GetFileNameWithoutExtension(trackList[i]); convertedList[i] = SaveWav.SaveToPath(fileName, defaultPath + convertedPath, clip); } SetClip(); }
//Saves the last played sound clip to %userprofile%\AppData\Local\Packages\<productname>\LocalState as a .wav file if the inputted name is legal public void SaveCurrentSoundClip() { if (audioSource.clip != null) { string filename; bool nameIsLegal = true; if (!string.IsNullOrWhiteSpace(customName.text)) { //Check for symbols that are not allowed in file names foreach (var letter in customName.text) { if (illegalCharacters.Contains(letter)) { nameIsLegal = false; break; } } if (nameIsLegal) { filename = customName.text; if (File.Exists(Application.persistentDataPath + "\\" + customName.text + ".wav")) { customName.text += "(1)"; filename += "(1)"; } SaveWav.Save(filename, audioSource.clip); EditorUtility.DisplayDialog("File Saved", "File succesfully saved to " + Application.persistentDataPath, "Ok"); } else { EditorUtility.DisplayDialog("Illegal Name", "The name you put it contains an illegal character. Please input a different name.", "Ok"); } } else { filename = audioSource.clip.name; SaveWav.Save(filename, audioSource.clip); EditorUtility.DisplayDialog("File Saved", "File succesfully saved to " + Application.persistentDataPath, "Ok"); } } }
// Token: 0x06015970 RID: 88432 RVA: 0x0057FBB0 File Offset: 0x0057DDB0 public static bool Save(string filename, AudioClip clip) { global::Debug.Log(string.Format("SaveWav filename={0} samples={1} frequency={2} channels={3} length={4}", new object[] { filename, clip.samples, clip.frequency, clip.channels, clip.length })); if (!filename.ToLower().EndsWith(".wav")) { filename += ".wav"; } Directory.CreateDirectory(Path.GetDirectoryName(filename)); using (FileStream fileStream = SaveWav.CreateEmpty(filename)) { SaveWav.ConvertAndWrite(fileStream, clip); SaveWav.WriteHeader(fileStream, clip); } return(true); }
// Token: 0x06015972 RID: 88434 RVA: 0x0057FCB0 File Offset: 0x0057DEB0 public static AudioClip TrimSilence(List <float> samples, float min, int channels, int hz) { return(SaveWav.TrimSilence(samples, min, channels, hz, false, false)); }
// Token: 0x06015971 RID: 88433 RVA: 0x0057FC74 File Offset: 0x0057DE74 public static AudioClip TrimSilence(AudioClip clip, float min) { float[] array = new float[clip.samples]; clip.GetData(array, 0); return(SaveWav.TrimSilence(new List <float>(array), min, clip.channels, clip.frequency)); }