Class RealtimeTranscriber
- Namespace
- AssemblyAI.Realtime
- Assembly
- AssemblyAI.dll
Transcribes audio in real-time using AssemblyAI's real-time transcription service.
public sealed class RealtimeTranscriber : IAsyncDisposable, IDisposable, INotifyPropertyChanged
- Inheritance
-
RealtimeTranscriber
- Implements
- Inherited Members
Constructors
RealtimeTranscriber()
Create a new instance of the real-time transcriber.
public RealtimeTranscriber()
RealtimeTranscriber(RealtimeTranscriberOptions)
Create a new instance of the real-time transcriber.
public RealtimeTranscriber(RealtimeTranscriberOptions options)
Parameters
options
RealtimeTranscriberOptionsThe options for the real-time transcription service.
Fields
Closed
The event raised when the connection with the real-time service is closed.
public readonly Event<ClosedEventArgs> Closed
Field Value
ErrorReceived
The event raised when an error message is received.
public readonly Event<RealtimeError> ErrorReceived
Field Value
ExceptionOccurred
The event raised when an exception occurs while listening for WebSocket messages.
public readonly Event<Exception> ExceptionOccurred
Field Value
FinalTranscriptReceived
The event raised when a final transcript is received.
public readonly Event<FinalTranscript> FinalTranscriptReceived
Field Value
PartialTranscriptReceived
The event raised when a partial transcript is received.
public readonly Event<PartialTranscript> PartialTranscriptReceived
Field Value
SessionBegins
The event raised when the real-time transcription session begins.
public readonly Event<SessionBegins> SessionBegins
Field Value
SessionInformationReceived
The event raised when session information is received, right before the session is terminated.
public readonly Event<SessionInformation> SessionInformationReceived
Field Value
TranscriptReceived
The event raised when a partial or final transcript is received.
public readonly Event<RealtimeTranscript> TranscriptReceived
Field Value
Properties
ApiKey
Use your AssemblyAI API key to authenticate with the AssemblyAI real-time transcriber.
public string? ApiKey { set; }
Property Value
DisablePartialTranscripts
Disable partial transcripts.
Set to true
to not receive partial transcripts. Defaults to false
.
public bool DisablePartialTranscripts { get; set; }
Property Value
Encoding
The encoding of the audio data
public AudioEncoding? Encoding { get; set; }
Property Value
RealtimeUrl
The Streaming STT endpoint to connect to.
public string RealtimeUrl { get; set; }
Property Value
SampleRate
The sample rate of the streamed audio. Defaults to 16000.
public uint SampleRate { get; set; }
Property Value
Status
The status of the real-time transcriber.
public RealtimeTranscriberStatus Status { get; }
Property Value
Token
Use a temporary auth token to authenticate with the AssemblyAI real-time transcriber. Learn how to generate a temporary token here.
public string? Token { set; }
Property Value
WordBoost
Add up to 2500 characters of custom vocabulary
public IEnumerable<string> WordBoost { get; set; }
Property Value
Methods
CloseAsync()
Terminate the real-time transcription session and close the connection.
public Task CloseAsync()
Returns
CloseAsync(bool)
Terminate the real-time transcription session and close the connection.
public Task CloseAsync(bool waitForSessionTerminated)
Parameters
waitForSessionTerminated
boolWait to receive pending transcripts and session terminated message.
Returns
ConfigureEndUtteranceThresholdAsync(uint)
Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
public Task ConfigureEndUtteranceThresholdAsync(uint threshold)
Parameters
threshold
uintThe duration of the end utterance silence threshold in milliseconds. This value must be an integer between 0 and 20_000.
Returns
ConnectAsync()
Connect to AssemblyAI's real-time transcription service, and start listening for messages.
public Task<SessionBegins> ConnectAsync()
Returns
- Task<SessionBegins>
The session begins message
Dispose()
Terminates the real-time transcription session, closes the connection, and disposes the real-time transcriber.
public void Dispose()
Remarks
Any remaining partial or final transcripts will not be received. To receive remaining partial or final transcripts, call CloseAsync() before disposing.
DisposeAsync()
Terminates the real-time transcription session, closes the connection, and disposes the real-time transcriber.
public ValueTask DisposeAsync()
Returns
Remarks
Any remaining partial or final transcripts will not be received. To receive remaining partial or final transcripts, call CloseAsync() before disposing.
ForceEndUtteranceAsync()
Manually end an utterance
public Task ForceEndUtteranceAsync()
Returns
SendAudioAsync(ArraySegment<byte>)
Send audio to the real-time service.
public Task SendAudioAsync(ArraySegment<byte> audio)
Parameters
audio
ArraySegment<byte>Audio to transcribe
Returns
SendAudioAsync(byte[])
Send audio to the real-time service.
public Task SendAudioAsync(byte[] audio)
Parameters
audio
byte[]Audio to transcribe
Returns
SendAudioAsync(Memory<byte>)
Send audio to the real-time service.
public Task SendAudioAsync(Memory<byte> audio)
Parameters
Returns
Events
PropertyChanged
PropertyChanged event is called when a property is changed.
public event PropertyChangedEventHandler? PropertyChanged