T-one Streaming ASR Pipeline

repository·main·Indexed 43 days ago

https://github.com/voicekit-team/t-one

A high-performance, streaming CTC-based Automatic Speech Recognition (ASR) pipeline optimized for the Russian language and telephony domain. T-one features a modular architecture with a Conformer acoustic model, phrase splitter, and Greedy or KenLM-based decoders. It supports offline and real-time streaming inference via the StreamingCTCPipeline class and provides options for high-performance deployment using NVIDIA TensorRT and Triton Inference Server.

Tokens
12.8K
Snippets
39
Records
53
Agent score
53%

What's inside T-one

  1. How the T-one ASR pipeline works

    main

    T-one is a streaming CTC-based ASR pipeline optimized for Russian telephony. It operates in three main stages:

    1. Acoustic Model (Conformer-based): Incoming audio is sliced into 300 ms segments. The model processes a segment along with a hidden state from the previous segment to maintain context. It outputs frame-level log-probabilities (logprobs) for the Russian alphabet (letters, space, and a blank token).
    2. Log-probability Splitter: This component uses the logprobs to detect speech boundaries. A phrase starts at the first speech frame and ends after $N$ consecutive non-speech frames. It outputs detected phrases with start/end timestamps.
    3. Decoder: Converts logprobs into text using one of two methods:
      • Greedy decoding: Fast, direct selection.
      • Beam Search decoding: Uses a KenLM language model for higher accuracy.

    This modular design allows for low-latency, high-throughput processing.

  2. Optimize acoustic model performance with TensorRT

    main

    To achieve maximum performance for the streaming acoustic model, you should choose between two primary configurations:

    1. Baseline: Microsoft ONNX Runtime + Nvidia Triton Inference Server. This is easier to use but slower.
    2. High Performance: NVIDIA TensorRT + NVIDIA Triton Inference Server. This is significantly faster (2-3x improvement) but requires converting the model into the TensorRT format.

    Before running performance tests, ensure the model is exported to ONNX or TensorRT and is running within a Triton Inference Server.

  3. Calculate Speech Per Second (SPS) throughput

    main

    When analyzing perf_analyzer results, you can calculate the actual Speech Per Second (SPS) throughput using the following formula:

    SPS = inferences/sec * chunk size (sec)

    For example, if the model processes 3000 inferences per second and each chunk represents 0.3 seconds of audio, the throughput is 3000 * 0.3 = 900 SPS.

  4. Install T-one locally

    main

    To install T-one for development or local usage, ensure you have Python 3.9+ and Poetry 2.1+ installed.

    Note for Windows users: The dependency kenlm does not officially support Windows. It is highly recommended to use Linux or WSL (Windows Subsystem for Linux).

    Method 1: Using Makefile

    If you have cloned the repository, you can use the provided Makefile:

    make install
    make up_dev

    This will install dependencies and start the demo web service.

    Method 2: Manual Poetry Installation

    1. Clone the repository:
      git clone https://github.com/voicekit-team/T-one.git
      cd T-one
    2. Create and activate a virtual environment:
      python -m venv .venv
      source .venv/bin/activate
    3. Install the package with demo dependencies:
      poetry install -E demo
    4. Run the demo web-service using uvicorn:
      uvicorn --host 0.0.0.0 --port 8080 tone.demo.website:app --reload
    poetry install -E demo
    uvicorn --host 0.0.0.0 --port 8080 tone.demo.website:app --reload
  5. Deploy the model in Triton Inference Server

    main

    To deploy the T-one acoustic model in Triton for high performance, you must organize the model files into a specific directory structure and use the appropriate configuration file.

    1. Directory Structure

    Create the following hierarchy in your models directory:

    models
    └── streaming_acoustic
        ├── 1
        │   └── model.onnx OR model.plan
        └── config.pbtxt

    2. Configuration Selection

    Copy the correct config.pbtxt from the configs directory based on your runtime:

    • For ONNX Runtime: Use configs/streaming_acoustic/config.pbtxt.
    • For TensorRT: Use configs/streaming_acoustic_trt/config.pbtxt.

    3. Model Preparation

    • For ONNX Runtime: Download the model into the version folder: python -m tone download $(pwd)/models/streaming_acoustic/1 --only-acoustic
    • For TensorRT: Convert the ONNX model to TensorRT format using the trtexec instructions provided in the export guide. TensorRT 10.x is supported.

    4. Run the Server

    Launch the Triton server using Docker, mapping the necessary ports and your model repository volume.

    # Run Triton Inference Server
    docker run --rm \
      -p 8000:8000 -p 8001:8001 -p 8002:8002 \
      -v $(pwd)/models:/models \
      nvcr.io/nvidia/tritonserver:25.06-py3 \
      tritonserver --model-repository=/models
  6. Install and run the T-one web service locally

    main

    To run the demonstration web service from source on Linux or macOS, follow these steps:

    1. Clone the repository:
      git clone https://github.com/voicekit-team/T-one.git
      cd T-one
    2. Create and activate a virtual environment:
      python -m venv .venv
      source .venv/bin/activate
    3. Use the provided Makefile to install and start development mode:
      make install
      make up_dev
    4. Open http://localhost:8080 in your browser.

    Alternative (Manual Poetry installation): If you prefer using Poetry directly:

    poetry install -E demo
    uvicorn --host 0.0.0.0 --port 8080 tone.demo.website:app --reload
    make install
    make up_dev
  7. Export the model to TensorRT

    main

    TensorRT engines are hardware-dependent and must be compiled on the specific target configuration (e.g., specific GPU and CUDA version) to ensure optimal performance. Follow these steps to compile the model:

    1. Download the ONNX model: Use the tone module to download only the acoustic component.
    2. Compile with trtexec: Use the NVIDIA Triton container to convert the ONNX model into a .plan engine file. You should adjust $BATCH_SIZE to balance throughput and latency for your specific device.

    Input Shape Details:

    • minShapes: The minimum batch size is 1. The input tensor length is 2400 (calculated as sample_rate * chunk_size, e.g., 8000 * 0.3). The state size is 219729.
    • optShapes and maxShapes: Use your chosen $BATCH_SIZE for these dimensions.

    After compilation, trtexec will output a performance metrics report.

    # 1. Download ONNX model
    python -m tone download $(pwd)/models/model.onnx --only-acoustic
    
    # 2. Compile to TensorRT
    docker run --rm -it \
      -v $(pwd)/models:/models \
      nvcr.io/nvidia/tritonserver:25.06-py3 \
      /usr/src/tensorrt/bin/trtexec \
        --onnx=/models/model.onnx \
        --minShapes=signal:1x2400x1,state:1x219729 \
        --optShapes=signal:$BATCH_SIZEx2400x1,state:$BATCH_SIZEx219729 \
        --maxShapes=signal:$BATCH_SIZEx2400x1,state:$BATCH_SIZEx219729 \
        --builderOptimizationLevel=5 \
        --stronglyTyped \
        --useSpinWait \
        --noDataTransfers \
        --saveEngine=/models/model.plan
  8. Quick start with T-one Docker demo

    main

    To quickly test the T-one streaming ASR pipeline with a web interface, run the pre-built Docker image. This allows you to transcribe audio files or use your microphone directly in your browser.

    Requirements:

    • At least 4 CPU cores
    • 8 GB RAM

    Steps:

    1. Run the container:
      docker run -it --rm -p 8080:8080 tinkoffcreditsystems/t-one:0.1.0
    2. Open http://localhost:8080 in your browser.

    Alternatively, you can build and run it locally:

    docker build -t t-one .
    docker run -it --rm -p 8080:8080 t-one
    docker run -it --rm -p 8080:8080 tinkoffcreditsystems/t-one:0.1.0
  9. Install dependencies for model fine-tuning

    main

    To fine-tune the T-one model, you need to install the specific finetune dependency group using Poetry:

    poetry install -E finetune

    Refer to examples/finetune_example.ipynb for a practical implementation guide.

  10. Install fine-tuning dependencies

    main

    To fine-tune the T-one model, install the package with the finetune extra using Poetry:

    poetry install -E finetune

    Refer to examples/finetune_example.ipynb for a complete notebook example of the fine-tuning process.

  11. Benchmark ONNX or TensorRT models with perf_analyzer

    main

    The perf_analyzer tool from the Triton SDK can be used to test both ONNX and TensorRT models.

    Setup: Run the Triton SDK container. Note: Use version 24.02 to avoid an Out-of-Memory (OOM) issue present in version 25.06.

    docker run --rm -it --net host \
      nvcr.io/nvidia/tritonserver:24.02-py3-sdk

    Running the benchmark: Execute perf_analyzer with parameters optimized for streaming ASR.

    Key Flags:

    • --sequence-length: Input sequence length. Note that sequence-length = 1 corresponds to 300ms of audio.
    • --request-rate-range: The range of request frequencies to test.
    • --latency-threshold: Latency threshold in milliseconds.
    • -u: URL of the server.
    • -i: Protocol (e.g., grpc).
    • -m: Model name.
    • --streaming: Enables streaming mode.
    perf_analyzer -u localhost:8001 \
      -i grpc \
      -a \
      -m streaming_acoustic \
      --streaming \
      --sequence-length=50 \
      --measurement-mode=count_windows \
      --measurement-request-count=5000 \
      --request-rate-range=2048:4096:256 \
      --stability-percentage=100 \
      --latency-threshold=100
  12. Quick start with Docker

    main

    The fastest way to try T-one is using a pre-built Docker image which includes a web interface for audio file recognition and microphone streaming.

    Requirements: Minimum 4 CPU cores and 8 GB RAM recommended.

    1. Run the container:
      docker run -it --rm -p 8080:8080 tinkoffcreditsystems/t-one:0.1.0
    2. Access the web interface at http://localhost:8080.
    docker run -it --rm -p 8080:8080 tinkoffcreditsystems/t-one:0.1.0