AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
DictationRecordButton.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity.InputModule.Tests
7 {
9  {
10  [SerializeField]
11  [Range(0.1f, 5f)]
12  [Tooltip("The time length in seconds before dictation recognizer session ends due to lack of audio input in case there was no audio heard in the current session.")]
13  private float initialSilenceTimeout = 5f;
14 
15  [SerializeField]
16  [Range(5f, 60f)]
17  [Tooltip("The time length in seconds before dictation recognizer session ends due to lack of audio input.")]
18  private float autoSilenceTimeout = 20f;
19 
20  [SerializeField]
21  [Range(1, 60)]
22  [Tooltip("Length in seconds for the manager to listen.")]
23  private int recordingTime = 10;
24 
25  [SerializeField]
26  private TextMesh speechToTextOutput = null;
27 
28  [SerializeField]
29  private GameObject recordLight = null;
30 
31  private Renderer buttonRenderer;
32 
33  private bool isRecording;
34 
35  private void Awake()
36  {
37  buttonRenderer = GetComponent<Renderer>();
38  }
39 
40  public void OnInputClicked(InputClickedEventData eventData)
41  {
42  ToggleRecording();
43  }
44 
45  private void ToggleRecording()
46  {
47  if (isRecording)
48  {
49  isRecording = false;
50  StartCoroutine(DictationInputManager.StopRecording());
51  speechToTextOutput.color = Color.white;
52  buttonRenderer.enabled = true;
53  recordLight.SetActive(false);
54  }
55  else
56  {
57  isRecording = true;
59  gameObject,
60  initialSilenceTimeout,
61  autoSilenceTimeout,
62  recordingTime));
63  speechToTextOutput.color = Color.green;
64  recordLight.SetActive(true);
65  buttonRenderer.enabled = false;
66  }
67  }
68 
70  {
71  speechToTextOutput.text = eventData.DictationResult;
72  }
73 
74  public void OnDictationResult(DictationEventData eventData)
75  {
76  speechToTextOutput.text = eventData.DictationResult;
77  }
78 
79  public void OnDictationComplete(DictationEventData eventData)
80  {
81  speechToTextOutput.text = eventData.DictationResult;
82  }
83 
84  public void OnDictationError(DictationEventData eventData)
85  {
86  isRecording = false;
87  speechToTextOutput.color = Color.red;
88  buttonRenderer.enabled = true;
89  recordLight.SetActive(false);
90  speechToTextOutput.text = eventData.DictationResult;
91  Debug.LogError(eventData.DictationResult);
92  StartCoroutine(DictationInputManager.StopRecording());
93  }
94  }
95 }
Singleton class that implements the DictationRecognizer to convert the user&#39;s speech to text...
Interface to implement dictation events.
Interface to implement to react to simple click input.
static IEnumerator StopRecording()
Ends the recording session.
string DictationResult
String result of the current dictation.
Describes an input event that involves a tap.
static IEnumerator StartRecording(GameObject listener=null, float initialSilenceTimeout=5f, float autoSilenceTimeout=20f, int recordingTime=10)
Turns on the dictation recognizer and begins recording audio from the default microphone.