simulstream.client.wav_reader_client

Functions

cli_main()

Simulstream WebSocket client command-line interface (CLI) entry point.

float32_to_int16(audio_data)

Convert a NumPy array of float32 audio samples to int16 PCM format.

load_wav_file_list(list_file_path)

Load a list of WAV file paths from a text file.

main(args)

Main entrypoint: validates WAV files and starts streaming.

read_wav_file(filename)

Read a WAV file and return its sample rate and audio data.

send_audio(websocket, sample_rate, data[, ...])

Stream audio data in fixed-size chunks over a WebSocket connection.

stream_wav_files(uri, wav_file_list[, ...])

Stream multiple WAV files sequentially to a WebSocket server.

simulstream.client.wav_reader_client.cli_main()

Simulstream WebSocket client command-line interface (CLI) entry point.

This script implements a simple WebSocket client that streams audio data from a list of WAV files to a server for processing (e.g., speech recognition or translation). It reads WAV files, converts them into fixed-size chunks, and sends them asynchronously over a WebSocket connection.

Example usage:

$ python wav_reader_client.py --uri ws://localhost:8000/ --wav-list-file wav_files.txt \
      --tgt-lang it --src-lang en

Command-line arguments:

  • --uri: WebSocket server URI (e.g., ws://localhost:8000/).

  • --wav-list-file: Path to a text file containing one WAV file path per line.

  • --chunk-duration-ms: Duration of each audio chunk sent to the server (ms). Default: 100.

  • --tgt-lang: Optional target language.

  • --src-lang: Optional source language.

simulstream.client.wav_reader_client.float32_to_int16(audio_data: ndarray) ndarray

Convert a NumPy array of float32 audio samples to int16 PCM format.

simulstream.client.wav_reader_client.load_wav_file_list(list_file_path: str) List[str]

Load a list of WAV file paths from a text file.

Parameters:

list_file_path (str) – Path to a text file, one WAV file path per line.

Returns:

Absolute file paths of WAV files.

Return type:

list[str]

async simulstream.client.wav_reader_client.main(args: Namespace)

Main entrypoint: validates WAV files and starts streaming.

simulstream.client.wav_reader_client.read_wav_file(filename: str) Tuple[int, ndarray]

Read a WAV file and return its sample rate and audio data.

Parameters:

filename (str) – Path to the WAV file.

Returns:

Sample rate and mono audio data as int16 array.

Return type:

tuple[int, np.ndarray]

Raises:
async simulstream.client.wav_reader_client.send_audio(websocket: ClientConnection, sample_rate: int, data: ndarray, chunk_duration_ms: int = 100)

Stream audio data in fixed-size chunks over a WebSocket connection.

Parameters:
  • websocket (websockets.ClientConnection) – Active WebSocket connection.

  • sample_rate (int) – Audio sample rate (Hz).

  • data (np.ndarray) – Audio samples as int16 array.

  • chunk_duration_ms (int) – Duration of each chunk in milliseconds.

async simulstream.client.wav_reader_client.stream_wav_files(uri: str, wav_file_list: List[str], chunk_duration_ms: int = 100, tgt_lang: str | None = None, src_lang: str | None = None)

Stream multiple WAV files sequentially to a WebSocket server.

For each file:
  • Sends metadata (sample rate, filename, optional languages).

  • Streams audio in chunks.

  • Sends an end-of-stream marker.

  • Waits for server confirmation before proceeding.

Parameters:
  • uri (str) – WebSocket server URI.

  • wav_file_list (list[str]) – Paths to WAV files.

  • chunk_duration_ms (int) – Chunk size in milliseconds.

  • tgt_lang (str | None) – Target language code (e.g., “en”).

  • src_lang (str | None) – Source language code (e.g., “en”).