PushAudioInputStream class

Represents memory backed push audio input stream used for custom audio input configurations. PushAudioInputStream

Extends

Methods

close()

Closes the stream.

commit(number)

Requests that the audio written so far be finalized as a completed segment, without ending or restarting the current recognition turn.

The call is non-blocking. The commit is anchored to the audio written before the call, so write the audio for the segment first, then call this method.

The request is advisory. A token is issued as soon as the request is recorded, but there is no guarantee that it will be acknowledged: the service may not support inline commit, or the session may end first. Applications must tolerate a token that is never echoed. A commit not yet delivered when the stream is closed is discarded, since end of audio finalizes the same audio.

Supported with SpeechRecognizer, TranslationRecognizer and ConversationTranscriber, for PCM, A-law and mu-law audio.

Throws if the stream has been closed, or if channelId is not an integer from 0 to 4294967295.

create(AudioStreamFormat)

Creates a memory backed PushAudioInputStream with the specified audio format.

write(ArrayBuffer)

Writes the audio data specified by making an internal copy of the data.

Inherited Methods

createPullStream(PullAudioInputStreamCallback, AudioStreamFormat)

Creates a PullAudioInputStream that delegates to the specified callback interface for read() and close() methods.

createPushStream(AudioStreamFormat)

Creates a memory backed PushAudioInputStream with the specified audio format.

Method Details

close()

Closes the stream.

function close()

commit(number)

Requests that the audio written so far be finalized as a completed segment, without ending or restarting the current recognition turn.

The call is non-blocking. The commit is anchored to the audio written before the call, so write the audio for the segment first, then call this method.

The request is advisory. A token is issued as soon as the request is recorded, but there is no guarantee that it will be acknowledged: the service may not support inline commit, or the session may end first. Applications must tolerate a token that is never echoed. A commit not yet delivered when the stream is closed is discarded, since end of audio finalizes the same audio.

Supported with SpeechRecognizer, TranslationRecognizer and ConversationTranscriber, for PCM, A-law and mu-law audio.

Throws if the stream has been closed, or if channelId is not an integer from 0 to 4294967295.

function commit(channelId?: number): number

Parameters

channelId

number

Optional 0-based index of the channel to commit on multichannel input. If omitted, the commit applies to all channels.

Returns

number

A token greater than 0 that the recognition result acknowledging the commit carries in its commitToken property, or 0 if the request was rejected: more than one commit within 100 ms on this stream, or an audio format that does not support commit.

create(AudioStreamFormat)

Creates a memory backed PushAudioInputStream with the specified audio format.

static function create(format?: AudioStreamFormat): PushAudioInputStream

Parameters

format
AudioStreamFormat

The audio data format in which audio will be written to the push audio stream's write() method (Required if format is not 16 kHz 16bit mono PCM).

Returns

The push audio input stream being created.

write(ArrayBuffer)

Writes the audio data specified by making an internal copy of the data.

function write(dataBuffer: ArrayBuffer)

Parameters

dataBuffer

ArrayBuffer

The audio buffer of which this function will make a copy.

Inherited Method Details

createPullStream(PullAudioInputStreamCallback, AudioStreamFormat)

Creates a PullAudioInputStream that delegates to the specified callback interface for read() and close() methods.

static function createPullStream(callback: PullAudioInputStreamCallback, format?: AudioStreamFormat): PullAudioInputStream

Parameters

callback
PullAudioInputStreamCallback

The custom audio input object, derived from PullAudioInputStreamCallback

format
AudioStreamFormat

The audio data format in which audio will be returned from the callback's read() method (Required if format is not 16 kHz 16bit mono PCM).

Returns

The audio input stream being created.

Inherited From AudioInputStream.createPullStream

createPushStream(AudioStreamFormat)

Creates a memory backed PushAudioInputStream with the specified audio format.

static function createPushStream(format?: AudioStreamFormat): PushAudioInputStream

Parameters

format
AudioStreamFormat

The audio data format in which audio will be written to the push audio stream's write() method (Required if format is not 16 kHz 16bit mono PCM).

Returns

The audio input stream being created.

Inherited From AudioInputStream.createPushStream