Class SpeechlyClient
Create a new Speechly Spoken Language Understading (SLU) Client to process speech and provide the results of automatic speech recogition (ASR) and natural langugage understanding (NLU) using delegates.
Usage
- Create a new SpeechlyClient instance.
- Create an SLU decoder (CloudDecoder) and pass it to
SpeechlyClient's Initialize(IDecoder, AudioProcessorOptions, ContextOptions, Boolean). - Attach delegates like OnSegmentChange to listen to and handle the SLU results.
- Feed audio to process with ProcessAudio(Single[], Int32, Int32).
- (delegates are firing up as speech is processed)
- When you don't need SLU services any more call Shutdown() to free resources.
You can feed audio continuously, but control when to start and stop process speech with Start(String) and Stop() or let voice activity detection (VAD) handle that automatically by passing EnergyThresholdVAD to SpeechlyClient constructor.
Inheritance
Namespace: Speechly.SLUClient
Assembly: speechly-dotnet.dll
Syntax
public class SpeechlyClient : object
Constructors
| Improve this Doc View SourceSpeechlyClient(Boolean, String, AudioInfo, Boolean)
Create a new SpeechlyClient to process audio and fire delegates to provide SLU results.
Declaration
public SpeechlyClient(bool manualUpdate = false, string saveToFolder = null, AudioInfo output = null, bool debug = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | manualUpdate | Setting |
| System.String | saveToFolder | Defines a local folder to save utterance files as 16 bit, 16000 Hz mono raw. Null disables saving. (default: |
| AudioInfo | output | |
| System.Boolean | debug | Enable debug prints thru Log delegate. (default: |
Fields
| Improve this Doc View Sourcedebug
Declaration
public bool debug
Field Value
| Type | Description |
|---|---|
| System.Boolean |
OnEntity
Declaration
public EntityDelegate OnEntity
Field Value
| Type | Description |
|---|---|
| EntityDelegate |
OnIntent
Declaration
public IntentDelegate OnIntent
Field Value
| Type | Description |
|---|---|
| IntentDelegate |
OnSegmentChange
Read the combined results of automatic speech recoginition (ASR) and natural language detection (NLU).
You can control when to start and stop process speech either manually with Start(String) and Stop(). Alternatively, you may let SpeechlyClient control this automatically by setting setting AudioProcessorOptions.VADControlsListening to true upon SpeechlyClient.Initialize() or by calling SpeechlyClient.AdjustAudioProcessor(true).
Declaration
public SegmentChangeDelegate OnSegmentChange
Field Value
| Type | Description |
|---|---|
| SegmentChangeDelegate |
OnStart
Declaration
public StartDelegate OnStart
Field Value
| Type | Description |
|---|---|
| StartDelegate |
OnStartStream
Declaration
public StartStreamDelegate OnStartStream
Field Value
| Type | Description |
|---|---|
| StartStreamDelegate |
OnStop
Declaration
public StopDelegate OnStop
Field Value
| Type | Description |
|---|---|
| StopDelegate |
OnStopStream
Declaration
public StopStreamDelegate OnStopStream
Field Value
| Type | Description |
|---|---|
| StopStreamDelegate |
OnTentativeEntity
Declaration
public TentativeEntityDelegate OnTentativeEntity
Field Value
| Type | Description |
|---|---|
| TentativeEntityDelegate |
OnTentativeIntent
Declaration
public IntentDelegate OnTentativeIntent
Field Value
| Type | Description |
|---|---|
| IntentDelegate |
OnTentativeTranscript
Declaration
public TentativeTranscriptDelegate OnTentativeTranscript
Field Value
| Type | Description |
|---|---|
| TentativeTranscriptDelegate |
OnTranscript
Declaration
public TranscriptDelegate OnTranscript
Field Value
| Type | Description |
|---|---|
| TranscriptDelegate |
Properties
| Improve this Doc View SourceAudioInputStreamIdentifier
Declaration
public string AudioInputStreamIdentifier { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
IsActive
Declaration
public bool IsActive { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsAudioStreaming
Declaration
public bool IsAudioStreaming { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsReady
Declaration
public bool IsReady { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Output
Declaration
public AudioInfo Output { get; }
Property Value
| Type | Description |
|---|---|
| AudioInfo |
Methods
| Improve this Doc View SourceAdjustAudioProcessor(Nullable<Boolean>)
Control AudioProcessor parameters.
Declaration
public void AdjustAudioProcessor(bool? vadControlsListening = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Nullable<System.Boolean> | vadControlsListening |
|
Initialize(IDecoder, AudioProcessorOptions, ContextOptions, Boolean)
SLU decoder instance to use like CloudDecoder.
The SLU decoder provides the automatic speech recognition (ASR) and natural language understanding (NLU) capabilities via SLU delegates (OnSegmentChange, OnTranscript...).
Declaration
public async Task Initialize(IDecoder decoder, AudioProcessorOptions audioProcessorOptions = null, ContextOptions contextOptions = null, bool preferLibSpeechlyAudioProcessor = false)
Parameters
| Type | Name | Description |
|---|---|---|
| IDecoder | decoder | SLU decoder implementing IDecoder interface like CloudDecoder. |
| AudioProcessorOptions | audioProcessorOptions | |
| ContextOptions | contextOptions | |
| System.Boolean | preferLibSpeechlyAudioProcessor |
Returns
| Type | Description |
|---|---|
| Task | Task that completes when the decoder is ready. |
ProcessAudio(Stream)
Declaration
public void ProcessAudio(Stream fileStream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | fileStream |
ProcessAudio(Single[], Int32, Int32)
Process speech audio samples from a microphone or other audio source.
It's recommended to feed audio early and often instead of large chunks to benefit from real-time ASR and NLU output.
You can control when to start and stop process speech either manually with Start(String) and Stop(). Alternatively you may use automatic voice activity detection (VAD) with AudioProcessorOptions passed to Initialize(IDecoder, AudioProcessorOptions, ContextOptions, Boolean).
The audio is handled as follows:
- Downsample to 16kHz if needed
- Add to history ringbuffer
- Calculate energy (VAD)
- Automatic Start/Stop (VAD)
- Send utterance audio to a file
- Send utterance audio to Speechly SLU decoder
Declaration
public void ProcessAudio(float[] floats, int start = 0, int length = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single[] | floats | Array of float containing samples to feed to the audio pipeline. Each sample needs to be in range -1f..1f. |
| System.Int32 | start | Start index of audio to process in samples (default: |
| System.Int32 | length | Length of audio to process in samples or |
ProcessAudioFile(String)
Declaration
public void ProcessAudioFile(string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fileName |
Shutdown()
Closes any connections (e.g. cloud SLU) and frees resources.
Declaration
public async Task Shutdown()
Returns
| Type | Description |
|---|---|
| Task | Task that completes with the shutdown. |
Start(String)
Start listening for user speech and feeding it to the SLU decoder.
OnContextStart is triggered upon a call to Start. It's also triggered by automatic VAD activation.
You don't need to await this call if you don't need the utterance id.
Declaration
public Task<string> Start(string appId = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | appId | Cloud decoder only: The Speechly app id to connect to, if not the default. If specified, you must use project id based login with cloud decoder. |
Returns
| Type | Description |
|---|---|
| Task<System.String> | An unique utterance id. |
StartStream(String, Boolean)
StartStream should be called at start of a continuous audio stream. It resets the stream sample counters and history. For backwards compability, ProcessAudio and Start ensure it's been called.
OnStreamStart delegate is triggered upon a call to StartStream.
Declaration
public void StartStream(string streamIdentifier, bool auto = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | streamIdentifier | |
| System.Boolean | auto |
Stop()
Stop listening for user speech.
OnContextStop is triggered upon a call to Stop. It's also triggered by automatic VAD deactivation.
You don't need to await this call if you don't need the utterance id.
Declaration
public Task<string> Stop()
Returns
| Type | Description |
|---|---|
| Task<System.String> | An unique utterance id. |
StopStream(Boolean)
StopStream should be called at the end of a continuous audio stream.
OnStreamStop delegate is triggered upon a call to StopStream.
Declaration
public void StopStream(bool auto = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | auto |
Update()
Call Update in your game loop to fire Speechly delegates manually if you want them to run in main UI/Unity thread.
Declaration
public void Update()