void Start() { _audioStatus = EProcessingStatus.Idle; LogSystem.InstallDefaultReactors(); // Watson turn on loggin Runnable.Run(CreateAuthenticateServices()); _outputAudioSource = GetComponent <AudioSource>(); }
private IEnumerator ProcessText() { Debug.Log("ProcessText"); _audioStatus = EProcessingStatus.Processing; if (_outputAudioSource.isPlaying) { yield return(null); } string nextText = String.Empty; if (textQueue.Count < 1) { yield return(null); } else { nextText = textQueue.Dequeue(); Debug.Log(nextText); if (String.IsNullOrEmpty(nextText)) { yield return(null); } } // The method accepts a maximum of 5 KB of input text in the body of the request, and 8 KB for the URL and headers // Doc: https://cloud.ibm.com/apidocs/text-to-speech?code=unity#synthesize byte[] synthesizeResponse = null; AudioClip clip = null; _textToSpeechService.Synthesize( callback: (DetailedResponse <byte[]> response, IBMError error) => { synthesizeResponse = response.Result; clip = WaveFile.ParseWAV("message.wav", synthesizeResponse); //Place the new clip into the audio queue. audioQueue.Enqueue(clip); }, text: nextText, voice: $"en-{voice}", accept: "audio/wav" ); while (synthesizeResponse == null) { yield return(null); } // Set status to indicate text to speech processing task completed _audioStatus = EProcessingStatus.Idle; }
private void OnMessage(DetailedResponse <MessageResponse> response, IBMError error) { Debug.Log($"response = {response.Result}"); string textResponse; if (response.Result == null || response.Result.Output == null || response.Result.Output.Generic == null || response.Result.Output.Generic.Count < 1) { textResponse = "I don't know how to respond to that."; } else { textResponse = response.Result.Output.Generic[0].Text.ToString(); } SendResponse(textResponse); _assistantStatus = EProcessingStatus.Processed; }
public IEnumerator ProcessChat(string chatInput, bool welcome = false) { Debug.Log($"Processchat: {chatInput}"); // Set status to show that the chat input is being processed. _assistantStatus = EProcessingStatus.Processing; if ((String.IsNullOrEmpty(chatInput) && !welcome) || _assistantService == null) { yield return(null); } MessageInput messageInput = null; if (!welcome) { messageInput = new MessageInput() { Text = chatInput, Options = new MessageInputOptions() { ReturnContext = true } }; } MessageResponse messageResponse = null; _assistantService.Message( callback: OnMessage, assistantId: assistantId, sessionId: _sessionId, input: messageInput ); while (messageResponse == null) { yield return(null); } }
void Start() { LogSystem.InstallDefaultReactors(); Runnable.Run(CreateAuthenticateServices()); _assistantStatus = EProcessingStatus.Idle; }