Skip to content

Commit ca49669

Browse files
author
David Kline
authored
Merge pull request #338 from keveleigh/master
Adding StopSpeaking() to TextToSpeechManager
2 parents 8212457 + db37f6e commit ca49669

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Assets/HoloToolkit/Utilities/Scripts/TextToSpeechManager.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,33 @@ public void SpeakText(string text)
382382
#endif
383383
}
384384

385+
/// <summary>
386+
/// Returns whether or not the AudioSource is actively playing.
387+
/// </summary>
388+
/// <returns>
389+
/// True, if the AudioSource is playing. False, if the AudioSource is not playing or is null.
390+
/// </returns>
391+
public bool IsSpeaking()
392+
{
393+
if (audioSource != null)
394+
{
395+
return audioSource.isPlaying;
396+
}
397+
398+
return false;
399+
}
400+
401+
/// <summary>
402+
/// Stops text-to-speech playback.
403+
/// </summary>
404+
public void StopSpeaking()
405+
{
406+
if (IsSpeaking())
407+
{
408+
audioSource.Stop();
409+
}
410+
}
411+
385412
/// <summary>
386413
/// Gets or sets the audio source where speech will be played.
387414
/// </summary>

Assets/HoloToolkit/Utilities/Tests/TextToSpeechManagerTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private void GestureRecognizer_TappedEvent(InteractionSourceKind source, int tap
3636

3737
// If we have a text to speech manager on the target object, say something.
3838
// This voice will appear to emanate from the object.
39-
if (tts != null)
39+
if (tts != null && !tts.IsSpeaking())
4040
{
4141
// Get the name
4242
var voiceName = Enum.GetName(typeof(TextToSpeechVoice), tts.Voice);
@@ -47,6 +47,10 @@ private void GestureRecognizer_TappedEvent(InteractionSourceKind source, int tap
4747
// Speak message
4848
tts.SpeakText(msg);
4949
}
50+
else if (tts.IsSpeaking())
51+
{
52+
tts.StopSpeaking();
53+
}
5054
}
5155
}
5256

0 commit comments

Comments
 (0)