Class SpeechToTextRecorder
Implements
Inherited Members
Namespace: Glitch9.AIDevKit.Generators
Assembly: Glitch9.AIDevKit.Agent.dll
Syntax
[AddComponentMenu("AI DevKit/AI Generators/Speech-to-Text Recorder", 4)]
public class SpeechToTextRecorder : MonoBehaviour, ISpeechToTextRecorder
Fields
| Edit this page View SourceonIsRecordingChanged
Raised whenever the recording state changes. true = recording started, false = recording stopped.
Declaration
public UnityEvent<bool> onIsRecordingChanged
Field Value
| Type | Description |
|---|---|
| UnityEvent<bool> |
onMicrophoneLevelChanged
Raised each frame with the current microphone input level (0??).
Declaration
public UnityEvent<float> onMicrophoneLevelChanged
Field Value
| Type | Description |
|---|---|
| UnityEvent<float> |
onMicrophonePermissionGranted
Raised when microphone permission is granted or denied.
Declaration
public UnityEvent<bool> onMicrophonePermissionGranted
Field Value
| Type | Description |
|---|---|
| UnityEvent<bool> |
Properties
| Edit this page View SourceIsRecording
Returns true while the recorder is actively capturing audio from the microphone.
Declaration
public bool IsRecording { get; }
Property Value
| Type | Description |
|---|---|
| bool |
KeyCodeTrigger
Settings for keyboard-based recording trigger.
Only used when RecordingTrigger is KeyCode.
Declaration
public KeyCodeTrigger KeyCodeTrigger { get; }
Property Value
| Type | Description |
|---|---|
| KeyCodeTrigger |
Microphone
The device name of the microphone to record from. When set while recording is active, restarts the recording on the new device. If left empty, the platform default microphone will be used.
Declaration
public string Microphone { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Recorder
Core audio recorder that handles microphone input and recording logic.
Declaration
public StreamingAudioRecorder Recorder { get; }
Property Value
| Type | Description |
|---|---|
| StreamingAudioRecorder |
RecordingDuration
The maximum duration of a single recording session in seconds. Increase this value if users need to speak for longer than the default. Default: Glitch9.AIDevKit.AIDevKitConfig.DefaultRecordingLengthSec.
Declaration
public int RecordingDuration { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
RecordingTrigger
Determines how recording is triggered: Manual, KeyCode, or VoiceDetection.
Changing this at runtime reconfigures the underlying recorder.
Declaration
public RecordingTriggerType RecordingTrigger { get; set; }
Property Value
| Type | Description |
|---|---|
| RecordingTriggerType |
VoiceDetectionSettings
Settings for voice-activity-detection (VAD) based recording trigger.
Only used when RecordingTrigger is VoiceDetection.
Declaration
public VoiceDetectionTrigger VoiceDetectionSettings { get; }
Property Value
| Type | Description |
|---|---|
| VoiceDetectionTrigger |
Methods
| Edit this page View SourceConfigure(AudioRecorderSettings)
Applies new AudioRecorderSettings (sample rate, length, device, etc.) to the underlying recorder at runtime.
Declaration
public void Configure(AudioRecorderSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| AudioRecorderSettings | settings |
RegisterInputAudioBufferListener(Action<float[]>)
Registers a callback that receives raw PCM float samples as they arrive from the microphone. Useful for real-time visualization or custom processing.
Declaration
public void RegisterInputAudioBufferListener(Action<float[]> listener)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<float[]> | listener |
RegisterRecordingStoppedListener(Action<AudioClip>)
Registers a callback that fires when a recording session ends and the final UnityEngine.AudioClip is available.
Declaration
public void RegisterRecordingStoppedListener(Action<AudioClip> listener)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<AudioClip> | listener |
StartRecording()
Begins capturing audio from the configured microphone.
Declaration
public void StartRecording()
Exceptions
| Type | Condition |
|---|---|
| MissingComponentException | Thrown if the underlying StreamingAudioRecorder could not be created, or if no microphone device is assigned. |
StopRecordingAsync()
Stops the active recording and returns the captured UnityEngine.AudioClip after post-processing.
Returns null if the recording is too short, contains no audio data, or the component
is being destroyed.
Declaration
public UniTask<AudioClip> StopRecordingAsync()
Returns
| Type | Description |
|---|---|
| UniTask<AudioClip> |
UnregisterInputAudioBufferListener(Action<float[]>)
Unregisters a previously registered PCM sample callback. Safe to call even if the recorder has not been initialized.
Declaration
public void UnregisterInputAudioBufferListener(Action<float[]> listener)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<float[]> | listener |
UnregisterRecordingStoppedListener(Action<AudioClip>)
Unregisters a previously registered recording-stopped callback. Safe to call even if the recorder has not been initialized.
Declaration
public void UnregisterRecordingStoppedListener(Action<AudioClip> listener)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<AudioClip> | listener |