public AudioSave Copy() { AudioSave a = new AudioSave(); foreach (var item in AudioParam) { AudioParam ap = new AudioParam(); ap.name = item.name; ap.value = item.value; a.AudioParam.Add(ap); } return(a); }
// Start is called before the first frame update void Start() { GameObject audio_mute = GameObject.Find("AudioSaver"); AudioSave audio_saved = audio_mute.GetComponent <AudioSave>(); mute_value = audio_saved.mute; if (mute_value) { AudioListener.volume = 0; } else { AudioListener.volume = 1; } }
public override void Load(string s) { AudioSave save = null; if (!string.IsNullOrEmpty(s)) { save = JsonUtility.FromJson <AudioSave>(s); } if (save != null && save.AudioParam.Count > 0) { currentSettings = save; } else { currentSettings = defaultSaveSettings.Copy(); } foreach (var item in currentSettings.AudioParam) { audioMixer.SetFloat(item.name, db(item.value)); } singleton = this; }
IEnumerator RecognizeVoice() { AudioSource audio = GetComponentInChildren <AudioSource>(); audio.clip = Microphone.Start(null, false, 2, 16000); //audio.loop = true; //while (!(Microphone.GetPosition(null) > 0)) { } //Debug.Log("start playing... position is " + Microphone.GetPosition(null)); //textM.text = "start playing... position is " + Microphone.GetPosition(null); yield return(new WaitForSeconds(2)); //audio.Play(); AudioClip clip = audio.clip; string audioFile = AudioSave.Save("HoloUC_WavJp", clip); //textM.text = audioFile; //textM.text = "start getting token..."; //yield return new WaitForSeconds(1); var bingHeaders = new Dictionary <string, string>() { { "Ocp-Apim-Subscription-Key", apiKey } }; //Tokenの取得 //POSTで投げたいのでダミーとして空のバイト配列を入れている WWW www = new WWW(bingTokenUrl, new byte[1], bingHeaders); yield return(www); string bingToken = www.text; //textM.text = www.text; //SpeechAPIの呼び出し var headers = new Dictionary <string, string>() { { "Accept", @"application/json;text/xml" }, { "Method", "POST" }, { "Host", @"speech.platform.bing.com" }, { "Content-Type", @"audio/wav; codec=""audio/pcm""; samplerate=16000" }, { "Authorization", "Bearer " + bingToken } }; byte[] buffer = null; using (FileStream fs = new FileStream(audioFile, FileMode.Open, FileAccess.Read)) { buffer = new Byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); } WWW wwwAPI = new WWW(bingAPIUrl, buffer, headers); yield return(wwwAPI); //textM.text = wwwAPI.text; var myResponse = JsonUtility.FromJson <MySpeechResponse>(wwwAPI.text); DoSthByVoice(myResponse.DisplayText); }
private void OnGUI() { selectedDeviceIndex = EditorGUILayout.Popup(selectedDeviceIndex, Microphone.devices); recordingLength = EditorGUILayout.IntField("Time", recordingLength); recordingFrequency = EditorGUILayout.IntField("Frequency", recordingFrequency); trimOnSave = EditorGUILayout.Toggle("Trim On Save", trimOnSave); trimLevel = EditorGUILayout.FloatField("Silence Level", trimLevel); if (Microphone.devices.Length > 0) { if (!Microphone.IsRecording(Microphone.devices[selectedDeviceIndex])) { if (GUILayout.Button("Record")) { recording = Microphone.Start(Microphone.devices[selectedDeviceIndex], false, recordingLength, recordingFrequency); savedClip = null; } } else { if (GUILayout.Button("Stop Recording")) { Microphone.End(Microphone.devices[selectedDeviceIndex]); } } } else { EditorGUILayout.HelpBox("Can't find Microphone Devices.", MessageType.Warning); EditorGUI.BeginDisabledGroup(isRecompiling); if (GUILayout.Button("Attempt Fix")) { UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation(); void Fix(object o) { isRecompiling = false; UnityEditor.Compilation.CompilationPipeline.compilationFinished -= Fix; } UnityEditor.Compilation.CompilationPipeline.compilationFinished -= Fix; UnityEditor.Compilation.CompilationPipeline.compilationFinished += Fix; isRecompiling = true; } EditorGUI.EndDisabledGroup(); } EditorGUI.BeginDisabledGroup(EditorApplication.timeSinceStartup < lockedUntil); if ((recording || savedClip)) { if (GUILayout.Button("Play")) { if (Microphone.devices.Length > 0 && Microphone.IsRecording(Microphone.devices[selectedDeviceIndex])) { Microphone.End(Microphone.devices[selectedDeviceIndex]); } PlayClip(recording ?? savedClip); lockedUntil = EditorApplication.timeSinceStartup + (recording ? recording.length : savedClip.length); } } if (recording) { if (GUILayout.Button("Save Clip")) { if (Microphone.IsRecording(Microphone.devices[selectedDeviceIndex])) { Microphone.End(Microphone.devices[selectedDeviceIndex]); } string path = EditorUtility.SaveFilePanel("Save Recorded Clip", folderPath, "recording", "wav"); path = Datahandling.EnsureAssetDataPath(path); AudioSave.Save(path, recording, true, trimLevel); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); recording = null; savedClip = AssetDatabase.LoadAssetAtPath <AudioClip>(path); folderPath = path.Substring(0, path.LastIndexOf("/")); Debug.Log(folderPath); } } EditorGUI.EndDisabledGroup(); }