services:
  speakr:
    image: voice-speakr:runtime
    container_name: voice-speakr
    restart: unless-stopped
    working_dir: /app
    env_file:
      - ./config.env
    environment:
      PYTHONPATH: /app
      SQLALCHEMY_DATABASE_URI: sqlite:////data/instance/transcriptions.db
      UPLOAD_FOLDER: /data/uploads
      USE_ASR_ENDPOINT: "true"
      ASR_BASE_URL: http://asr-test:59805
    volumes:
      - ./speakr:/app
      - ./deploy/data/speakr/uploads:/data/uploads
      - ./deploy/data/speakr/instance:/data/instance
    ports:
      - "8899:8899"
    depends_on:
      - asr-test
      - voice-dected
    command:
      - sh
      - -c
      - >
        mkdir -p /data/uploads /data/instance &&
        python -c "from src.app import app; from src.clients import db; app.app_context().push(); db.create_all()" &&
        exec gunicorn --workers $${GUNICORN_WORKERS:-3} --threads $${GUNICORN_THREADS:-8}
        --bind 0.0.0.0:8899 --timeout $${GUNICORN_TIMEOUT:-600} src.app:app

  voice-dected:
    image: voice-dected:runtime
    container_name: voice-dected
    restart: unless-stopped
    working_dir: /app
    env_file:
      - ./config.env
    environment:
      PYTHONPATH: /app
    volumes:
      - ./voice-dected/src:/app
    ports:
      - "18000:8000"
    command:
      - uvicorn
      - app:app
      - --host
      - 0.0.0.0
      - --port
      - "8000"

  asr-test:
    image: paraformer-asr:latest
    container_name: asr-test
    restart: unless-stopped
    runtime: nvidia
    gpus:
      - driver: nvidia
        device_ids:
          - "7"
        capabilities:
          - gpu
    working_dir: /app
    env_file:
      - ./config.env
    environment:
      DEVICE: cuda
      CUDA_VISIBLE_DEVICES: "0"
      NVIDIA_VISIBLE_DEVICES: "7"
      VOICE_DETECTED_URL: http://voice-dected:8000
      VOICEPRINT_STORE: /data/asr_voiceprints.json
    volumes:
      - ./asr/main.py:/app/main.py:ro
      - /storage01/home/xll/audio:/app/audio:ro
      - /storage01/home/xll/weixiu-hj/seacomodel:/app/models/seacomodel:ro
      - /storage01/home/xll/weixiu-hj/vadmodel:/app/models/vadmodel:ro
      - /storage01/home/xll/weixiu-hj/ctpuncmodel:/app/models/ctpuncmodel:ro
      - /storage01/home/xll/weixiu-hj/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/example/hotword.txt:/app/hotword.txt:ro
      - ./deploy/data/asr:/data
    ports:
      - "59805:59805"
    depends_on:
      - voice-dected
    command:
      - uvicorn
      - main:app
      - --host
      - 0.0.0.0
      - --port
      - "59805"
      - --workers
      - "1"


  funasr-online:
    image: paraformer-asr:latest
    container_name: funasr-online
    restart: unless-stopped
    runtime: nvidia
    gpus:
      - driver: nvidia
        device_ids:
          - "7"
        capabilities:
          - gpu
    working_dir: /app/funasr_runtime
    env_file:
      - ./config.env
    environment:
      DEVICE: cuda
      CUDA_VISIBLE_DEVICES: "0"
      NVIDIA_VISIBLE_DEVICES: "7"
      MODELSCOPE_CACHE: /models
      TORCH_HOME: /models/torch
    volumes:
      - ./funasr_runtime:/app/funasr_runtime:ro
      - ./deploy/data/funasr-models:/models
    ports:
      - "10096:10096"
    command:
      - python
      - funasr_wss_server.py
      - --host
      - 0.0.0.0
      - --port
      - "10096"
      - --ngpu
      - "1"
      - --device
      - cuda
      - --ncpu
      - "4"
      - --asr_model_online
      - iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online
      - --vad_model
      - iic/speech_fsmn_vad_zh-cn-16k-common-pytorch
      - --punc_model
      - iic/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727
      - --worker_threads
      - "4"
      - --concurrent_asr_online
      - "1"
      - --concurrent_asr_offline
      - "1"
      - --concurrent_vad
      - "1"
      - --concurrent_punc
      - "1"
      - --certfile
      - ""
      - --keyfile
      - ""

  funasr-runtime-2pass:
    image: registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.13
    container_name: funasr-runtime-2pass
    restart: unless-stopped
    working_dir: /workspace/FunASR/runtime
    volumes:
      - ./deploy/data/funasr-runtime-models:/workspace/models
    ports:
      - "10097:10095"
    command:
      - bash
      - -lc
      - >
        touch /workspace/models/hotwords.txt &&
        exec /workspace/FunASR/runtime/websocket/build/bin/funasr-wss-server-2pass
        --download-model-dir /workspace/models
        --vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx
        --model-dir damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx
        --online-model-dir damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online-onnx
        --punc-dir damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727-onnx
        --lm-dir damo/speech_ngram_lm_zh-cn-ai-wesp-fst
        --itn-dir thuduj12/fst_itn_zh
        --decoder-thread-num 4
        --model-thread-num 1
        --io-thread-num 1
        --port 10095
        --hotword /workspace/models/hotwords.txt
        --certfile ""
        --keyfile ""

  fastapi-wss:
    image: fastapi-wss:runtime
    container_name: fastapi-wss
    restart: unless-stopped
    working_dir: /app/src
    env_file:
      - ./config.env
    environment:
      TARGET_WS_URL: ws://funasr-runtime-2pass:10095
      REDIS_URL: redis://redis:6379/0
      VOICEPRINT_STORE: /data/asr/asr_voiceprints.json
      SPEAKER_DET_URL: http://voice-dected:8000/extract_embedding
      REALTIME_VOICEPRINT_ENABLED: "true"
      REALTIME_VOICEPRINT_WINDOW_SECONDS: "2.0"
    volumes:
      - ./fastapi_wss:/app
      - ./deploy/data/asr:/data/asr:ro
    ports:
      - "10095:10095"
    depends_on:
      - funasr-runtime-2pass
      - voice-dected
      - redis
    command:
      - python
      - a2a_wss.py

  redis:
    image: redis:7-alpine
    container_name: voice-redis
    restart: unless-stopped
    volumes:
      - ./deploy/data/redis:/data
    ports:
      - "16380:6379"
    command:
      - redis-server
      - --appendonly
      - "yes"
