Skip to content

Commit 4e6c2f4

Browse files
committed
Adding IsSpeaking to TTSManager
1 parent eea97ba commit 4e6c2f4

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Assets/HoloToolkit/Utilities/Scripts/TextToSpeechManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,22 @@ 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+
385401
/// <summary>
386402
/// Stops text-to-speech playback.
387403
/// </summary>

Assets/HoloToolkit/Utilities/Tests/TextToSpeechManagerTest.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ public class TextToSpeechManagerTest : MonoBehaviour
99
{
1010
private GestureRecognizer gestureRecognizer;
1111
public TextToSpeechManager textToSpeechManager;
12-
private bool isSpeaking;
1312

1413
// Use this for initialization
1514
void Start ()
1615
{
17-
isSpeaking = false;
18-
1916
// Set up a GestureRecognizer to detect Select gestures.
2017
gestureRecognizer = new GestureRecognizer();
2118
gestureRecognizer.TappedEvent += GestureRecognizer_TappedEvent;
@@ -39,22 +36,19 @@ private void GestureRecognizer_TappedEvent(InteractionSourceKind source, int tap
3936

4037
// If we have a text to speech manager on the target object, say something.
4138
// This voice will appear to emanate from the object.
42-
if (tts != null && !isSpeaking)
39+
if (tts != null && !tts.IsSpeaking())
4340
{
4441
// Get the name
4542
var voiceName = Enum.GetName(typeof(TextToSpeechVoice), tts.Voice);
4643

4744
// Create message
4845
var msg = string.Format("This is the {0} voice. It should sound like it's coming from the object you clicked. Feel free to walk around and listen from different angles.", voiceName);
4946

50-
isSpeaking = true;
51-
5247
// Speak message
5348
tts.SpeakText(msg);
5449
}
55-
else if (isSpeaking)
50+
else if (tts.IsSpeaking())
5651
{
57-
isSpeaking = false;
5852
tts.StopSpeaking();
5953
}
6054
}

0 commit comments

Comments
 (0)