private async Task SpeakAsync(string toSpeak) { if (_speechSynthesizer == null) { _speechSynthesizer = new SpeechSynthesizer(); var voice = SpeechSynthesizer.AllVoices.Where(v => v.Gender == VoiceGender.Female && v.Language.Contains("en")).FirstOrDefault(); if (voice != null) { _speechSynthesizer.Voice = voice; } } var syntStream = await _speechSynthesizer.SynthesizeTextToStreamAsync(toSpeak); await SoundUtilities.PlaySound(syntStream.AsStream()); }
/// <summary> /// Spielt einen Clip /// </summary> /// <param name="pi_Clips">Clip</param> /// <param name="pi_Volume">Optional Lautstärke</param> /// <param name="pi_HasToPlay">Optional muss gespielt werden</param> private void PlaySound(AudioClip pi_Clip, float pi_Volume = 1.0f, bool pi_HasToPlay = true) { //------------------------------------------------------ //Falls der Sound unterbrechen darf //------------------------------------------------------ if (!pi_HasToPlay) { //------------------------------------------------------ //Spiele Sound auf der entsprechenden Quelle //------------------------------------------------------ float l_OldVol = m_MustnPlay.volume; m_MustnPlay.volume = pi_Volume; SoundUtilities.PlaySound(m_MustnPlay, pi_Clip); m_MustnPlay.volume = l_OldVol; return; } //------------------------------------------------------ //Versuche eine Source zu finden die nicht benutzt wird //------------------------------------------------------ foreach (AudioSource b_Source in m_AddedSources) { if (!b_Source.isPlaying) { //------------------------------------------------------ //Spiele ggf. //------------------------------------------------------ float l_OldVol = b_Source.volume; b_Source.volume = pi_Volume; SoundUtilities.PlaySound(b_Source, pi_Clip); b_Source.volume = l_OldVol; return; } } //------------------------------------------------------ //Füge neue Source hinzu //------------------------------------------------------ m_AddedSources.Add(SoundUtilities.AddSourceToObject(gameObject, false, 1.0f, false)); //------------------------------------------------------ //Versuche erneut //------------------------------------------------------ PlaySound(pi_Clip, pi_Volume); }