private IEnumerator WaitForAudioFinishedCallback(float time, TextToSpeech.AudioFinishedCallback followupCallback) { yield return(new WaitForSeconds(time)); _voiceProcessor.Active = true; if (followupCallback != null) { followupCallback(); } }
private IEnumerator StartTextSynthesis(string text, TextToSpeech.AudioFinishedCallback followupCallback) { Log.Debug("ScriptReader", "Attempting synthesize"); _voiceProcessor.Active = false; _textToSpeech.Voice = VoiceType.en_US_Michael; //VoiceType.en_US_Allison; _textToSpeech.ToSpeech(text, HandleToSpeechCallback, true, null, followupCallback); while (!_synthesizeTested) { yield return(null); } }
private void PlayClip(AudioClip clip, TextToSpeech.AudioFinishedCallback followupCallback) { if (Application.isPlaying && clip != null) { GameObject audioObject = new GameObject("AudioObject"); AudioSource source = audioObject.AddComponent <AudioSource>(); source.spatialBlend = 0.0f; source.loop = false; source.clip = clip; source.Play(); Destroy(audioObject, clip.length); StartCoroutine(WaitForAudioFinishedCallback(clip.length, followupCallback)); _synthesizeTested = true; } }
public void ReadText(string text, TextToSpeech.AudioFinishedCallback followupCallback) { StartCoroutine(StartTextSynthesis(text, followupCallback)); }
void HandleToSpeechCallback(AudioClip clip, string customData, TextToSpeech.AudioFinishedCallback followupCallback) { PlayClip(clip, followupCallback); }