public bool GenerateAudioFromText(string text, Voices voice) { if (isPlaying || voice == null) { return(false); } SpeachToTextCommand command = new SpeachToTextCommand { action = "speechSynthesis", activityAddress = MagicRoomManager.instance.HttpListenerForMagiKRoom.Address + ":" + MagicRoomManager.instance.HttpListenerForMagiKRoom.Port + "/" + endpoint, text = text, voice = voice.name }; MagicRoomManager.instance.Logger.AddToLogNewLine("ServerTTSO", text + "," + voice.name + " started"); StartCoroutine(SendCommand(command, (body) => { isPlaying = true; StartSpeak?.Invoke(); }, () => { StartSpeak?.Invoke(); EndSpeak?.Invoke(); isPlaying = false; })); return(true); }
private void GetConfiguration() { SpeachToTextCommand command = new SpeachToTextCommand { action = "getVoicesList" }; StartCoroutine(SendCommand(command, (body) => { SpeachToTextOfflineConfiguration conf = JsonUtility.FromJson <SpeachToTextOfflineConfiguration>(body); ListOfVoice.Clear(); ListOfVoice.AddRange(conf.voices); string log = ""; foreach (Voices s in ListOfVoice) { log += "Available " + s.name + " as a voice, "; } MagicRoomManager.instance.Logger.AddToLogNewLine("ServerTTSO", log); })); }
public void generateAudioFromText(string text, Voices voice, string filename) { if (!MagicRoomSpeachToText_active) { return; } if (File.Exists(Application.streamingAssetsPath + "/audio/" + filename)) { return; } command = new SpeachToTextCommand(); command.action = "speechSynthesis"; command.activityAddress = HttpListenerForMagiKRoom.instance.address + ":" + HttpListenerForMagiKRoom.instance.port + "/" + receivigCodeExpression; command.filename = filename + ".mp3"; command.lang = voice.voiceLang; command.path = Application.streamingAssetsPath + "/audio/"; command.text = text; command.voice = voice.voiceName; StartCoroutine(sendCommand()); Logger.addToLogNewLine("ServerTTS", text + "," + voice.voiceName); }
private IEnumerator SendCommand(SpeachToTextCommand command, MagicRoomManager.WebCallback callback = null, UnityAction errorCallback = null) { string json = JsonUtility.ToJson(command); byte[] body = new System.Text.UTF8Encoding().GetBytes(json); UnityWebRequest request = new UnityWebRequest(address, "POST") { uploadHandler = new UploadHandlerRaw(body), downloadHandler = new DownloadHandlerBuffer() }; request.SetRequestHeader("Content-Type", "application/json"); yield return(request.SendWebRequest()); if (!request.isNetworkError) { callback?.Invoke(request.downloadHandler.text); } else { errorCallback?.Invoke(); } }
IEnumerator getConfigurationFromServer() { command = new SpeachToTextCommand(); command.action = "getVoicesList"; string json = JsonUtility.ToJson(command); print(json); byte[] myData = System.Text.Encoding.UTF8.GetBytes(json); UnityWebRequest www = UnityWebRequest.Put(address, myData); //UnityWebRequest www = UnityWebRequest.Post(address, json); www.SetRequestHeader("Content-Type", "application/json"); yield return(www.Send()); if (www.isNetworkError) { if (www.error == "Cannot connect to destination host") { MagicRoomSpeachToText_active = false; } } else { MagicRoomSpeachToText_active = true; Debug.Log(www.downloadHandler.text); SpeachToTextCommandConfiguration conf = new SpeachToTextCommandConfiguration(); conf = JsonUtility.FromJson <SpeachToTextCommandConfiguration>(www.downloadHandler.text); listofAssociatedNames = conf.voices; string log = ""; foreach (Voices s in listofAssociatedNames) { log += "Available " + s.voiceName + " as a voice, "; } Logger.addToLogNewLine("ServerTTS", log); } }