Skip to content

Commit

Permalink
Merge pull request microsoft#338 from keveleigh/master
Browse files Browse the repository at this point in the history
Adding StopSpeaking() to TextToSpeechManager
  • Loading branch information
David Kline authored Nov 23, 2016
2 parents 8212457 + db37f6e commit ca49669
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Assets/HoloToolkit/Utilities/Scripts/TextToSpeechManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,33 @@ public void SpeakText(string text)
#endif
}

/// <summary>
/// Returns whether or not the AudioSource is actively playing.
/// </summary>
/// <returns>
/// True, if the AudioSource is playing. False, if the AudioSource is not playing or is null.
/// </returns>
public bool IsSpeaking()
{
if (audioSource != null)
{
return audioSource.isPlaying;
}

return false;
}

/// <summary>
/// Stops text-to-speech playback.
/// </summary>
public void StopSpeaking()
{
if (IsSpeaking())
{
audioSource.Stop();
}
}

/// <summary>
/// Gets or sets the audio source where speech will be played.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private void GestureRecognizer_TappedEvent(InteractionSourceKind source, int tap

// If we have a text to speech manager on the target object, say something.
// This voice will appear to emanate from the object.
if (tts != null)
if (tts != null && !tts.IsSpeaking())
{
// Get the name
var voiceName = Enum.GetName(typeof(TextToSpeechVoice), tts.Voice);
Expand All @@ -47,6 +47,10 @@ private void GestureRecognizer_TappedEvent(InteractionSourceKind source, int tap
// Speak message
tts.SpeakText(msg);
}
else if (tts.IsSpeaking())
{
tts.StopSpeaking();
}
}
}

Expand Down

0 comments on commit ca49669

Please sign in to comment.