Interface AudioSource

ru.yandex.speechkit

public  interface  AudioSource 

Interface for an audio source.

Used by classes that recognize speech: Recognizer and PhraseSpotter. Any audio source can be used: standard device input, remote source, and so on.

Use of any audio source works as follows:
  • Creating and starting an object that provides sound data. When an audio source is ready to transmit data to listeners, it should send a message to each subscribed listener using the onAudioSourceStarted(AudioSource) method. If a new listener subscribes while the audio source is running, it also receives a message upon subscription (via the onAudioSourceStarted(AudioSource) method).

  • Transmitting data to listeners by fragments at a certain interval. Data is transmitted using the onAudioSourceData(AudioSource, ByteBuffer) method. The interval is set using the getBufferCaptureTimeout() method. Listeners can request this value before subscribing to an audio source.

  • Upon completion of the audio source operation, listeners should be notified of that via the onAudioSourceStopped(AudioSource) method. At the time when the audio source stops, the number of listeners may decrease, as they may unsubscribe in the process of its operation. For example, OnlineRecognizer unsubscribes when the end of speech is detected.

Methods

intgetBufferCaptureTimeout()

The interval between the audio fragments that the audio source sends to the listeners.

SoundInfogetSoundInfo()

Returns information on the audio that will be transmitted by this audio source.

voidstop()

Completes audio recording.

voidsubscribe(@NonNull final AudioSourceListener listener)

This method subscribes a listener that implements the AudioSourceListener interface.

voidunsubscribe(@NonNull final AudioSourceListener listener)

This method unsubscribes the listener that implements the AudioSourceListener interface.

Method Detail

getBufferCaptureTimeout

public int getBufferCaptureTimeout ()

The interval between the audio fragments that the audio source sends to the listeners.

Returns:

The interval between the audio fragments that the audio source sends to the listeners.

getSoundInfo

public SoundInfo getSoundInfo ()

Returns information on the audio that will be transmitted by this audio source.

Returns:

Information on the audio that will be transmitted by this audio source.

stop

public void stop ()

Completes audio recording.

The method is executed synchronously and releases all the resources used by an object of the AudioSource class. If an audio was recorded during the method invocation, the listeners will have the onAudioSourceStopped(AudioSource) method called.

subscribe

public void subscribe (@NonNull final AudioSourceListener listener)

This method subscribes a listener that implements the AudioSourceListener interface.

Parameters:
listener

A listener that will receive messages on the audio source status and audio data.

unsubscribe

public void unsubscribe (@NonNull final AudioSourceListener listener)

This method unsubscribes the listener that implements the AudioSourceListener interface.

Parameters:
listener

A listener that receives messages about the status of an audio source and audio data.