Skip to content

Commit fa79615

Browse files
committed
updated stt readme to include information on how to get data from the microphone
1 parent 6ea7bc8 commit fa79615

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

Scripts/Services/SpeechToText/v1/README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,40 @@ private void HandleGetModel(Model result, string customData)
6868
```
6969

7070
### Recognize audio
71+
#### Accessing the device microphone and sending data to the Speech to Text instance
72+
You can access the microphone of a device using Unity's Microphone class.
73+
74+
```cs
75+
_speechToText.StartListening(OnRecognize);
76+
_recording = Microphone.Start(<device-name>, <loop>, <length-seconds>, <frequency>);
77+
```
78+
79+
AudioData can be created using the resulting AudioClip
80+
```cs
81+
int midPoint = _recording.samples / 2;
82+
samples = new float[midPoint];
83+
_recording.GetData(samples, 0);
84+
85+
AudioData record = new AudioData();
86+
record.MaxLevel = Mathf.Max(samples);
87+
record.Clip = AudioClip.Create("Recording", midPoint, _recording.channels, _recordingHZ, false);
88+
record.Clip.SetData(samples, 0);
89+
```
90+
91+
The AudioData can be sent to the Speech to Text service and handled by the OnRecognize callback
92+
```cs
93+
_speechToText.OnListen(record);
94+
```
95+
96+
```cs
97+
private void OnRecognize(SpeechRecognitionEvent result)
98+
{
99+
// do something
100+
}
101+
```
102+
103+
Please see `ExampleStreaming` scene for an example.
104+
71105
#### Streaming mode
72106

73107
For requests to transcribe live audio as it becomes available or to transcribe multiple audio files with multipart requests, you must set the Transfer-Encoding header to chunked to use streaming mode. In streaming mode, the server closes the connection (status code 408) if the service receives no data chunk for 30 seconds and the service has no audio to transcribe for 30 seconds. The server also closes the connection (status code 400) if no speech is detected for inactivity_timeout seconds of audio (not processing time); use the inactivity_timeout parameter to change the default of 30 seconds. An example of streaming from the Unity microphone is provided in the Examples directory.
@@ -91,8 +125,6 @@ An example of the multipart metadata for a pair of FLAC files follows. This firs
91125
metadata="{\"part_content_type\":\"audio/flac\",\"data_parts_count\":2,\"continuous\":true,\"inactivity_timeout\"=-1}"
92126
```
93127

94-
Note about the Try It Out feature: The Try it out! button is not supported for use with the the POST /v1/recognize method. For examples of calls to the method, see the [Speech to Text API reference][speech-to-text].
95-
96128
```cs
97129
private void Recognize()
98130
{

0 commit comments

Comments
 (0)