กลับไปหน้า Tools

GetNotes Tools

huggingface/speech-to-speech

Tool นี้คืออะไร

Speech To Speech เป็นเครื่องมือสำหรับสร้างระบบตัวแทนเสียง (voice agent) ที่มีความหน่วงต่ำและปรับเปลี่ยนได้ง่าย โดยใช้โมเดล Open Source เหมาะสำหรับนักพัฒนาที่ต้องการสร้างแอปพลิเคชันสนทนาด้วยเสียง หรือระบบควบคุมหุ่นยนต์ที่ใช้เสียงเป็นหลัก

ข้อมูลโปรเจกต์

ดาว

8.3K

Forks

1K

License

Apache-2.0

อัปเดต GitHub ล่าสุด

30 ก.ค. 2569

เพิ่มใน GetNotes

17 ส.ค. 2569

Repository

huggingface/speech-to-speech

เหมาะกับงาน

Automation

Ecosystem

Python

แปลและเรียบเรียงโดย AI

เนื้อหาฉบับภาษาไทย

ใช้อ่านเพื่อทำความเข้าใจเบื้องต้น โปรดตรวจสอบรายละเอียดสำคัญกับเอกสารต้นฉบับด้านล่าง

Speech To Speech: สร้างตัวแทนเสียงด้วยโมเดล Open Source

PyPI Python License GitHub Trending: #1 Repository of the Day

ไปป์ไลน์ตัวแทนเสียงที่มีความหน่วงต่ำและเป็นโมดูลาร์อย่างสมบูรณ์: VAD -> STT -> LLM -> TTS ซึ่งเปิดเผยผ่านชุดเหตุการณ์ OpenAI Realtime GA event set หลักผ่าน WebSocket และ WebRTC ทุกองค์ประกอบสามารถสลับเปลี่ยนได้ ช่อง LLM รองรับโปรโตคอลที่เข้ากันได้กับ OpenAI ดังนั้นคุณสามารถชี้ไปที่ผู้ให้บริการโฮสต์, ที่ HF Inference Providers, หรือที่เซิร์ฟเวอร์ vLLM หรือ llama.cpp บนฮาร์ดแวร์ของคุณเองสำหรับสแต็กที่เปิดกว้างและทำงานแบบโลคอลอย่างสมบูรณ์

ไปป์ไลน์นี้ทำงานในการผลิตในฐานะแบ็กเอนด์การสนทนาสำหรับหุ่นยนต์ Reachy Mini หลายพันตัว

เริ่มต้นใช้งานอย่างรวดเร็ว

bash
pip install speech-to-speech
export OPENAI_API_KEY=...
speech-to-speech serve

คำสั่งนี้จะเริ่มเซิร์ฟเวอร์ที่เข้ากันได้กับ OpenAI Realtime ที่ ws://localhost:8765/v1/realtime โดยใช้ Parakeet TDT สำหรับ STT แบบโลคอล, LLM ที่เข้ากันได้กับ OpenAI และ Qwen3-TTS สำหรับการสร้างเสียงพูดแบบโลคอล

พูดคุยกับมันจากเทอร์มินัลที่สอง:

bash
speech-to-speech talk --url ws://127.0.0.1:8765/v1/realtime

หากต้องการเริ่มเซิร์ฟเวอร์และไคลเอนต์ไมโครโฟน/ลำโพงที่มาพร้อมแพ็กเกจในคำสั่งเดียว:

bash
speech-to-speech local

ต้องการเก็บ LLM ไว้บนเครื่องของคุณเองหรือไม่? ให้บริการ Gemma 4 ด้วย llama.cpp:

bash
llama-server -hf ggml-org/gemma-4-E4B-it-GGUF -np 2 -c 65536 -fa on --swa-full

จากนั้นชี้แบ็กเอนด์ LLM ที่เข้ากันได้กับ OpenAI ไปที่มัน:

bash
speech-to-speech serve \
    --model_name "ggml-org/gemma-4-E4B-it-GGUF" \
    --responses_api_base_url "http://127.0.0.1:8080/v1" \
    --responses_api_api_key ""

ไคลเอนต์ที่ใช้ชุดเหตุการณ์ Realtime หลักที่นำมาใช้งานสามารถเชื่อมต่อได้ OpenAI Agents SDK อย่างเป็นทางการได้รับการทดสอบบนทั้งสองการส่งข้อมูลมาตรฐาน ดู Realtime API สำหรับส่วนที่ได้รับการทดสอบ และ LLM backends สำหรับตัวเลือกผู้ให้บริการและเซิร์ฟเวอร์โลคอล

สารบัญ

วิธีการทำงาน

ไปป์ไลน์เป็นลำดับของสี่ส่วนประกอบ แต่ละส่วนทำงานในเธรดของตัวเองและเชื่อมต่อกันด้วยคิว:

  1. 1Voice Activity Detection (VAD): Silero VAD v5 ตรวจจับขอบเขตของเสียงพูดและการสลับตาพูด
  2. 2Speech to Text (STT): ถอดเสียงพูดของผู้ใช้ โดยมีตัวเลือกการถอดเสียงบางส่วนแบบสด
  3. 3Language Model (LLM): สร้างการตอบสนอง โดยสตรีมข้อความและการเรียกใช้เครื่องมือ
  4. 4Text to Speech (TTS): สังเคราะห์เสียงและสตรีมกลับไปยังไคลเอนต์

แต่ละขั้นตอนมีแบ็กเอนด์ที่สลับเปลี่ยนได้หลายแบบ ซึ่งเลือกได้ผ่านแฟล็ก CLI โค้ดถูกออกแบบมาให้แก้ไขได้ง่าย โดยเน้นที่โมเดลที่มีให้ผ่าน Transformers และ Hugging Face Hub

การติดตั้ง

ต้องใช้ Python 3.10+

bash
pip install speech-to-speech

การติดตั้งเริ่มต้นครอบคลุมเส้นทางเรียลไทม์มาตรฐาน:

  • Parakeet TDT สำหรับ STT
  • API ที่เข้ากันได้กับ OpenAI สำหรับโมเดลภาษา
  • Qwen3-TTS สำหรับการสร้างเสียงพูด โดยใช้แบ็กเอนด์ GGML เป็นค่าเริ่มต้นบนแพลตฟอร์มที่ไม่ใช่ macOS และ mlx-audio บน Apple Silicon
  • โหมดเสียงโลคอลและเซิร์ฟเวอร์เรียลไทม์

การพึ่งพาของ macOS และที่ไม่ใช่ macOS จะถูกแก้ไขโดยอัตโนมัติผ่านตัวระบุแพลตฟอร์มใน pyproject.toml

ข้อควรทราบเกี่ยวกับ CUDA สำหรับ Qwen3-TTS

บน Linux แบ็กเอนด์ Qwen3-TTS GGML มาจาก faster-qwen3-tts[ggml] โดย qwentts-cpp-python wheel เริ่มต้นบน PyPI กำหนดเป้าหมาย CUDA 12.8 หากเครื่องของคุณไม่มีรันไทม์ CUDA 12 ที่ wheel คาดหวัง ให้ติดตั้ง wheel ที่ตรงกันจาก Hugging Face wheelhouse ก่อนติดตั้ง speech-to-speech:

bash
# CUDA 13.x
pip install "qwentts-cpp-python==0.3.1+cu130" \
  -f https://huggingface.co/datasets/andito/qwentts-cpp-python-wheels/tree/main/whl/cu130

# CUDA 12.4
pip install "qwentts-cpp-python==0.3.1+cu124" \
  -f https://huggingface.co/datasets/andito/qwentts-cpp-python-wheels/tree/main/whl/cu124

# CPU-only fallback
pip install "qwentts-cpp-python==0.3.1+cpu" \
  -f https://huggingface.co/datasets/andito/qwentts-cpp-python-wheels/tree/main/whl/cpu

pip install speech-to-speech

หากต้องการใช้การใช้งาน CUDA-graphs ก่อนหน้าแทน GGML ให้ส่ง --qwen3_tts_backend torch

ส่วนประกอบเสริม

ส่วนประกอบเสริมจะถูกติดตั้งด้วย pip extras:

bash
pip install "speech-to-speech[kokoro]"          # Kokoro-82M TTS บนแพลตฟอร์มที่ไม่ใช่ macOS
pip install "speech-to-speech[pocket]"          # Pocket TTS
pip install "speech-to-speech[chattts]"         # ChatTTS
pip install "speech-to-speech[faster-whisper]"  # Faster Whisper STT
pip install "speech-to-speech[whisper-mlx]"     # Lightning Whisper MLX STT บน macOS
pip install "speech-to-speech[paraformer]"      # Paraformer STT ผ่าน FunASR
pip install "speech-to-speech[mlx-lm]"          # รองรับ mlx-vlm สำหรับโมเดลวิชันบน macOS

การใช้งานที่เลิกใช้แล้ว รวมถึง MeloTTS อยู่ใน archive/ และไม่ได้เชื่อมต่อกับ CLI อีกต่อไป

หมายเหตุเกี่ยวกับ DeepFilterNet: DeepFilterNet ซึ่งใช้สำหรับการปรับปรุงเสียงเสริมใน VAD ต้องใช้ numpy<2 และขัดแย้งกับ Pocket TTS ซึ่งต้องใช้ numpy>=2 ติดตั้งด้วยตนเองเฉพาะในสภาพแวดล้อมที่คุณไม่ได้ใช้ Pocket TTS

จาก Source

bash
git clone https://github.com/huggingface/speech-to-speech.git
cd speech-to-speech
uv sync

คำสั่งนี้จะติดตั้งแพ็กเกจในโหมดแก้ไขได้และทำให้ CLI speech-to-speech พร้อมใช้งาน

ส่วนประกอบที่รองรับ

ส่วนประกอบแบ็กเอนด์แพลตฟอร์มการติดตั้ง
VADSilero VAD v5ทั้งหมดbuilt-in
STTParakeet TDT (ค่าเริ่มต้น)CUDA / CPU ผ่าน nano-parakeet, Apple Silicon ผ่าน MLXbuilt-in
STTWhisper ผ่าน TransformersCUDA / CPUbuilt-in
STTFaster WhisperCUDA / CPUfaster-whisper
STTLightning Whisper MLXApple Siliconwhisper-mlx
STTMLX Audio WhisperApple Siliconbuilt-in บน macOS
STTParaformerCUDA / CPUparaformer
LLMOpenAI-compatible API (responses-api, chat-completions)ผู้ให้บริการโฮสต์หรือเซิร์ฟเวอร์ที่โฮสต์เองbuilt-in
LLMTransformersCUDA / CPUbuilt-in
LLMmlx-lmApple Siliconbuilt-in บน macOS
TTSQwen3-TTS (ค่าเริ่มต้น)GGML / CUDA บน Linux, mlx-audio บน macOSbuilt-in
TTSKokoro-82MCUDA / CPU, Apple Siliconkokoro บนแพลตฟอร์มที่ไม่ใช่ macOS; built-in บน macOS
TTSPocket TTSCPU / CUDApocket
TTSChatTTSCUDA / CPUchattts
TTSMMS TTSCUDA / CPUbuilt-in

เลือกการใช้งานด้วย --stt, --llm_backend, และ --tts CLI จะสร้างการกำหนดค่าสำหรับแบ็กเอนด์ที่เลือกเท่านั้น ตัวเลือกที่ทราบสำหรับแบ็กเอนด์ที่ไม่ได้ใช้งานยังคงได้รับการยอมรับเพื่อความเข้ากันได้ แต่จะถูกละเว้นพร้อมคำเตือน การกำหนดค่า JSON อาจรวมคีย์แบ็กเอนด์ที่ไม่ได้ใช้งานเพิ่มเติม ซึ่งจะถูกละเว้น เรียกใช้ speech-to-speech serve -h สำหรับค่าเริ่มต้น หรือส่งตัวเลือกก่อน -h เพื่อดูแฟล็กเฉพาะแบ็กเอนด์ของการรวมกันอื่น (เช่น speech-to-speech serve --stt mlx-audio-whisper -h)

คำสั่ง

คำสั่งพฤติกรรมใช้เมื่อ
serveรันเซิร์ฟเวอร์ไปป์ไลน์ผ่าน OpenAI Realtime WebSocket และ WebRTCคุณกำลังสร้างแอปหรืออุปกรณ์ที่ใช้ API
talk --url <full-realtime-url>รันไคลเอนต์ไมโครโฟน/ลำโพงที่มาพร้อมแพ็กเกจคุณต้องการพูดคุยกับเซิร์ฟเวอร์ Realtime ที่มีอยู่
localรวม serve และ talk ในกระบวนการเดียวกันผ่าน loopbackคุณต้องการรันเซิร์ฟเวอร์และพูดคุยกับมันด้วยคำสั่งเดียว

serve จะผูกกับ 127.0.0.1 โดยค่าเริ่มต้น หากต้องการเปิดเผยบนเครือข่าย ให้ส่ง --host 0.0.0.0 อย่างชัดเจน local จะผูกกับ loopback เสมอและเชื่อมต่อไคลเอนต์ที่มาพร้อมแพ็กเกจเดียวกันที่ ws://127.0.0.1:<port>/v1/realtime

ไคลเอนต์ที่มาพร้อมแพ็กเกจสามารถเลือกใช้เครื่องมือ Python ภายในเครื่องได้ด้วย talk --tool-module <module> หรือ local --tool-module <module> สัญญาของโมดูล, API แบบโปรแกรม และตัวอย่างการค้นหาเว็บ Serper มีเอกสารอยู่ใน Tool calling design

การย้ายจาก --mode

--mode ถูกเลิกใช้งานแล้วและจะหยุดทำงานในไม่ช้า ในช่วงการย้ายข้อมูลนี้ speech-to-speech --mode realtime จะรัน speech-to-speech serve และ speech-to-speech --mode local จะรัน speech-to-speech local โดยทั้งคู่จะแสดงคำเตือน ค่าโหมดอื่นๆ ทั้งหมดถูกลบออกแล้วและจะออกพร้อมคำแนะนำให้ใช้คำสั่งใหม่

เซิร์ฟเวอร์ Realtime

bash
export OPENAI_API_KEY=...
speech-to-speech serve

นี่เทียบเท่ากับ:

bash
speech-to-speech serve \
    --thresh 0.6 \
    --stt parakeet-tdt \
    --llm_backend responses-api \
    --tts qwen3 \
    --qwen3_tts_model_name Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice \
    --qwen3_tts_speaker Aiden \
    --qwen3_tts_language auto \
    --qwen3_tts_backend ggml \
    --qwen3_tts_non_streaming_mode True \
    --qwen3_tts_mlx_quantization 6bit \
    --model_name gpt-5.4-mini \
    --chat_size 30 \
    --responses_api_stream \
    --enable_live_transcription

โมเดลเริ่มต้นคือ gpt-5.4-mini ผ่าน OpenAI Responses API คุณสามารถแทนที่ได้ด้วย --model_name และตั้งค่า --responses_api_base_url สำหรับผู้ให้บริการหรือเซิร์ฟเวอร์ที่เข้ากันได้กับ OpenAI อื่นๆ

Mac ภายในเครื่อง

bash
speech-to-speech local --mac-optimal-settings

เลือกใช้ LLM ที่เฉพาะเจาะจงได้:

bash
speech-to-speech local \
    --mac-optimal-settings \
    --model_name mlx-community/Qwen3-4B-Instruct-2507-bf16

การตั้งค่านี้:

  • ใช้ค่าเริ่มต้นของ MPS สำหรับส่วนประกอบโมเดลที่รองรับ
  • ตั้งค่า Parakeet TDT สำหรับ STT
  • ตั้งค่า MLX LM เป็นแบ็กเอนด์ LLM
  • ตั้งค่า Qwen3-TTS สำหรับ TTS โดยใช้ mlx-audio พร้อม MLX variant 6bit โดยค่าเริ่มต้น

ค่าที่ตั้งไว้ล่วงหน้าเหล่านี้เป็นค่าเริ่มต้นเท่านั้น: --device ที่ระบุอย่างชัดเจน, แฟล็กอุปกรณ์ส่วนประกอบ เช่น --qwen3_tts_device, และ --stt, --llm_backend, --model_name, และ --tts ทั้งหมดจะมีผลเหนือกว่า ใช้กับ serve แทน local เมื่อคุณต้องการเปิดเผยเซิร์ฟเวอร์โดยไม่ต้องเริ่มไคลเอนต์ไมโครโฟน/ลำโพง

--tts pocket และ --tts kokoro ก็ใช้ได้บน macOS เช่นกัน

หากต้องการเปรียบเทียบ MLX quantization variants ภายในเครื่อง:

bash
python scripts/benchmark_tts.py \
    --handlers qwen3 \
    --iterations 3 \
    --qwen3_mlx_quantizations bf16 4bit 6bit 8bit

Docker

ติดตั้ง NVIDIA Container Toolkit จากนั้น:

bash
docker compose up

ไฟล์ compose จะเริ่มเซิร์ฟเวอร์ llama.cpp พร้อม Gemma 4 และเซิร์ฟเวอร์ Realtime โดยเปิดพอร์ต 8080 และ 8765

Realtime API

โหมด Realtime รองรับโปรโตคอล OpenAI Realtime ผ่าน WebSocket และ WebRTC พร้อมการถอดเสียงแบบสดและการผลัดกันพูดที่ใช้เวลาแฝงต่ำ ไคลเอนต์ WebSocket เชื่อมต่อที่ /v1/realtime:

python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8765/v1",
    websocket_base_url="ws://localhost:8765/v1",
    api_key="not-needed",
)

with client.realtime.connect(model="local") as conn:
    conn.send(
        {
            "type": "session.update",
            "session": {
                "type": "realtime",
                "instructions": "You are a helpful assistant.",
                "audio": {
                    "input": {
                        "turn_detection": {
                            "type": "server_vad",
                            "interrupt_response": True,
                        }
                    }
                },
            },
        }
    )

    for event in conn:
        print(event.type)

เซิร์ฟเวอร์ใช้ชุดเหตุการณ์ Realtime หลัก: input_audio_buffer.append, session.update, conversation.item.create, conversation.item.truncate, response.create, และ response.cancel ขาเข้า; การเริ่ม/หยุดพูด, การถอดเสียงแบบสตรีมมิ่ง, การเปลี่ยนแปลงเสียง, การเรียกใช้เครื่องมือ, และ response.done ขาออก CI เชื่อมต่ออินสแตนซ์ @openai/agents RealtimeSession ที่ตรึงไว้ผ่าน WebSocket และ WebRTC transports มาตรฐานของ SDK นี่คือชุดย่อยหลักที่ผ่านการทดสอบแล้ว ไม่ใช่การอ้างสิทธิ์ความเท่าเทียมกันของ OpenAI Realtime API ทั้งหมด เมทริกซ์เหตุการณ์, สถาปัตยกรรม, และรายละเอียดการออกแบบอยู่ใน Realtime Engine README

LLM Proxy

ด้วย --enable_llm_proxy เซิร์ฟเวอร์ Realtime ยังเปิดเผย LLM ระยะไกลที่กำหนดค่าไว้เป็นปลายทางที่เข้ากันได้กับ OpenAI ธรรมดา ดังนั้นไคลเอนต์จึงสามารถรันงานเสริม (สรุป, หัวข้อ, เอเจนต์เบื้องหลัง) ด้วยเครื่องมือและการสตรีม โดยทำงานพร้อมกันกับการสนทนาด้วยเสียงและไม่ถูกขัดจังหวะด้วยเสียงพูดใหม่:

  • POST /v1/chat/completions เมื่อรัน --llm_backend chat-completions
  • POST /v1/responses เมื่อรัน --llm_backend responses-api

เซิร์ฟเวอร์ไม่ทำการตรวจสอบสิทธิ์และไม่จำกัดความเร็วด้วยตัวเอง เปิดใช้งานพร็อกซีเฉพาะบนเครือข่ายที่เชื่อถือได้ หรือปรับใช้เซิร์ฟเวอร์หลังเกตเวย์ที่ควบคุมการเข้าถึง s2s-endpoint compute replica เป็นเกตเวย์ดังกล่าว: มันเปิดเส้นทางเหล่านี้เฉพาะกับไคลเอนต์ที่สร้างเซสชันด้วยโทเค็น HF, ตรวจสอบคีย์ API กับโทเค็นนั้น, และใช้การจำกัดอัตราต่อผู้ใช้ ชี้ OpenAI SDK มาตรฐานไปยังโฮสต์ใดก็ตามที่คุณพูดคุยด้วย; เซิร์ฟเวอร์นี้จะละเว้นคีย์ API (เกตเวย์ด้านหน้าจะตัดสินใจว่าควรเป็นอะไร):

python
from openai import OpenAI

llm = OpenAI(base_url="http://localhost:8765/v1", api_key="unused")
completion = llm.chat.completions.create(
    model="anything",  # ถูกละเว้น: เซิร์ฟเวอร์บังคับใช้ --model_name ที่กำหนดค่าไว้
    messages=[{"role": "user", "content": "Summarize the conversation so far: ..."}],
)

คำขอเป็นแบบไร้สถานะ (ส่งรายการข้อความทั้งหมดทุกครั้ง) และจะถูกส่งผ่านไปยังต้นทางที่กำหนดค่าไว้ด้วยคีย์ที่เซิร์ฟเวอร์ถืออยู่ ซึ่งไม่เคยไปถึงไคลเอนต์ ฟิลด์ model จะถูกเขียนทับเสมอด้วย --model_name ที่กำหนดค่าไว้ในเซิร์ฟเวอร์ พร็อกซีปิดอยู่โดยค่าเริ่มต้น, ต้องใช้แบ็กเอนด์ระยะไกล (chat-completions หรือ responses-api), และจะตอบกลับด้วย 501 พร้อมเหตุผลในกรณีอื่น

LLM Backends

LLM เป็นส่วนประกอบที่ใช้การประมวลผลมากที่สุดและมีเวลาแฝงสูงที่สุดในไปป์ไลน์ การส่งผ่านโมเดลขนาดใหญ่เพียงครั้งเดียวสามารถครอบงำเวลาตอบสนองแบบ end-to-end ได้ ดังนั้นการเลือกแบ็กเอนด์ที่เหมาะสมสำหรับฮาร์ดแวร์และงบประมาณเวลาแฝงของคุณจึงเป็นสิ่งสำคัญ ไปป์ไลน์รองรับ:

  • การอนุมานภายในเครื่อง: transformers บน CUDA / CPU และ mlx-lm บน Apple Silicon
  • เซิร์ฟเวอร์ที่โฮสต์เอง: responses-api และ chat-completions สามารถชี้ไปยังเซิร์ฟเวอร์ vLLM หรือ llama.cpp ภายในเครื่องได้
  • Provider APIs: แบ็กเอนด์เดียวกันนี้ทำงานร่วมกับ OpenAI, HF Inference Providers, OpenRouter และผู้ให้บริการอื่นๆ ที่เข้ากันได้กับ OpenAI

มีแบ็กเอนด์ API สองตัวให้เลือกใช้ โดยใช้แฟล็กการเชื่อมต่อ --responses_api_* เดียวกัน:

  • --llm_backend responses-api (ค่าเริ่มต้น) กำหนดเป้าหมายไปที่ /v1/responses
  • --llm_backend chat-completions กำหนดเป้าหมายไปที่ /v1/chat/completions

การป้อนข้อมูลเสียงโดยตรง (ไม่มี STT)

ใช้ --stt none --llm_backend chat-completions เพื่อส่งส่วนเสียง VAD ที่สมบูรณ์แต่ละส่วนโดยตรงไปยังโมเดลที่รับอินพุตเสียง โหมดเสียงโดยตรงไม่รองรับกับ --llm_backend responses-api: โมเดลอาจยอมรับเสียงผ่าน /v1/chat/completions โดยไม่รองรับ /v1/responses รวมถึง gpt-audio-1.5 ของ OpenAI

คุณต้องตั้งค่า --model_name อย่างชัดเจนเป็นโมเดลที่รับเสียงได้: gpt-5.4-mini เริ่มต้นรับอินพุตข้อความและรูปภาพ แต่ไม่ใช่เสียง ตรวจสอบเอกสารโมเดลของผู้ให้บริการและการรองรับปลายทางก่อนเปิดใช้งานโหมดนี้ สำหรับ OpenAI โปรดดู GPT-5.4 mini model card และ audio-input guide

bash
speech-to-speech serve \
    --stt none \
    --llm_backend chat-completions \
    --model_name "YOUR_AUDIO_CAPABLE_MODEL" \
    --responses_api_base_url "https://provider.example/v1" \
    --responses_api_api_key "$PROVIDER_API_KEY"

เซิร์ฟเวอร์ที่เข้ากันได้กับ OpenAI แสดงอินพุตเสียงแตกต่างกัน ใช้ --responses_api_audio_content_type input_audio (ค่าเริ่มต้น) สำหรับ WAV base64 แบบฝัง หรือ --responses_api_audio_content_type audio_url สำหรับ URL ข้อมูล base64

ตัวอย่างด้านล่างจับคู่ Parakeet TDT สำหรับ STT แบบโลคัล และ Qwen3-TTS สำหรับ TTS แบบโลคัล กับ LLM แบ็กเอนด์ที่แตกต่างกัน

แบ็กเอนด์ Responses API

ทำงานร่วมกับผู้ให้บริการหรือเซิร์ฟเวอร์ใดๆ ที่ใช้ OpenAI Responses API ชี้ --responses_api_base_url ไปยังปลายทางและตั้งค่า --model_name ตามความเหมาะสม:

ผู้ให้บริการ / เซิร์ฟเวอร์--responses_api_base_url--responses_api_api_key
OpenAIละเว้น, ใช้ค่าเริ่มต้นของ OpenAI$OPENAI_API_KEY
HF Inference Providershttps://router.huggingface.co/v1$HF_TOKEN
OpenRouterhttps://openrouter.ai/api/v1$OPENROUTER_API_KEY
vLLMhttp://localhost:8000/v1ละเว้นหรือสตริงใดๆ
llama.cpphttp://127.0.0.1:8080/v1สตริงว่าง
bash
# OpenAI
speech-to-speech local \
    --stt parakeet-tdt \
    --llm_backend responses-api \
    --tts qwen3 \
    --qwen3_tts_mlx_quantization 6bit \
    --model_name "gpt-4o-mini" \
    --responses_api_api_key "$OPENAI_API_KEY" \
    --responses_api_stream \
    --enable_live_transcription
bash
# HF Inference Providers: Qwen3.5-9B via Together
speech-to-speech local \
    --stt parakeet-tdt \
    --llm_backend responses-api \
    --tts qwen3 \
    --qwen3_tts_mlx_quantization 6bit \
    --model_name "Qwen/Qwen3.5-9B:together" \
    --responses_api_base_url "https://router.huggingface.co/v1" \
    --responses_api_api_key "$HF_TOKEN" \
    --responses_api_stream \
    --enable_live_transcription
bash
# HF Inference Providers: GPT-oss-20B via Groq
speech-to-speech serve \
    --stt parakeet-tdt \
    --llm_backend responses-api \
    --tts qwen3 \
    --qwen3_tts_mlx_quantization 6bit \
    --model_name "openai/gpt-oss-20b:groq" \
    --responses_api_base_url "https://router.huggingface.co/v1" \
    --responses_api_api_key "$HF_TOKEN" \
    --responses_api_stream \
    --enable_live_transcription

แบ็กเอนด์ Chat Completions

การกำหนดค่าเหมือนกับ responses-api โดยใช้แฟล็กการเชื่อมต่อ --responses_api_* เดียวกัน แต่จะสื่อสารกับ /v1/chat/completions แทน /v1/responses ควรเลือกใช้เมื่อ:

  • ผู้ให้บริการละเลย chat_template_kwargs.enable_thinking บนพาธ Responses และต้องการปุ่ม reasoning_effort เพื่อระงับการให้เหตุผล หรือ
  • พาธการสตรีม tool-call ของเซิร์ฟเวอร์ Responses ไม่น่าเชื่อถือ ในขณะที่การสตรีม tool-call ของ Chat Completions นั้นเสถียร ซึ่งมีประโยชน์สำหรับ vLLM บางรุ่น ดูที่ #312

เพิ่ม --responses_api_reasoning_effort none เพื่อปิดใช้งานการให้เหตุผลบนผู้ให้บริการที่แฟล็ก chat-template ไม่มีผล:

bash
# vLLM serving a Qwen model with tool calling
speech-to-speech serve \
    --stt parakeet-tdt \
    --llm_backend chat-completions \
    --tts qwen3 \
    --model_name "Qwen/Qwen3-4B-Instruct-2507" \
    --responses_api_base_url "http://localhost:8000/v1" \
    --responses_api_stream
bash
# Gemma 4 31B via the HF router on Cerebras, with reasoning disabled for low voice latency
speech-to-speech serve \
    --stt parakeet-tdt \
    --llm_backend chat-completions \
    --tts qwen3 \
    --model_name "google/gemma-4-31B-it:cerebras" \
    --responses_api_base_url "https://router.huggingface.co/v1" \
    --responses_api_api_key "$HF_TOKEN" \
    --responses_api_reasoning_effort none \
    --responses_api_stream

โลคัลทั้งหมด

เรียกใช้ LLM ในกระบวนการ llama.cpp แยกต่างหากเพื่อการตั้งค่าโลคัลทั้งหมดที่ง่ายที่สุด ดังที่แสดงใน คู่มือการสนทนาโลคัล Reachy Mini:

สำหรับการตั้งค่าเสียงแบบเนทีฟแบบโลคัลทั้งหมดพร้อมเดโมในเบราว์เซอร์, การแก้ไขการพูดแบบเรียลไทม์ และ barge-in โปรดดู ตัวอย่าง speech-to-speech ของ Gemma 4 12B สำหรับ Apple Silicon ที่ผ่านการทดสอบแล้ว

bash
# Terminal 1: llama.cpp serving Gemma 4
llama-server -hf ggml-org/gemma-4-E4B-it-GGUF -np 2 -c 65536 -fa on --swa-full
bash
# Terminal 2: speech-to-speech using that local LLM server
speech-to-speech serve \
    --stt parakeet-tdt \
    --llm_backend responses-api \
    --tts qwen3 \
    --model_name "ggml-org/gemma-4-E4B-it-GGUF" \
    --responses_api_base_url "http://127.0.0.1:8080/v1" \
    --responses_api_api_key "" \
    --responses_api_stream \
    --enable_live_transcription

ใช้ speech-to-speech local เมื่อคุณต้องการเรียกใช้เซิร์ฟเวอร์เดียวกันและสื่อสารผ่านเครื่องที่โฮสต์มัน แบ็กเอนด์โลคัลแบบ In-process มีให้ใช้งานด้วย --llm_backend mlx-lm บน Apple Silicon หรือ --llm_backend transformers บน CUDA / CPU

การทำงานแบบออฟไลน์

ไปป์ไลน์สามารถทำงานได้โดยไม่ต้องเชื่อมต่ออินเทอร์เน็ตหลังจากติดตั้งส่วนประกอบที่เลือกและโมเดลที่เกี่ยวข้องในเครื่อง ก่อนที่จะตัดการเชื่อมต่อ ให้เริ่มการกำหนดค่าที่แน่นอนหนึ่งครั้งในขณะที่ออนไลน์ เพื่อให้สามารถแคชทรัพยากร STT, LLM, TTS, Silero VAD, NLTK และ Smart Turn ที่จำเป็นได้

สำหรับการตั้งค่า LLM แบบโลคัลทั้งหมดที่ง่ายที่สุด ให้เรียกใช้ llama.cpp บนเครื่องเดียวกันตามที่อธิบายไว้ใน โลคัลทั้งหมด เมื่อ llama.cpp และทรัพยากรไปป์ไลน์พร้อมใช้งานในเครื่องแล้ว ให้ตั้งค่า HF_HUB_OFFLINE=1 เมื่อเริ่ม speech-to-speech เพื่อป้องกันการร้องขอ Hugging Face Hub:

bash
HF_HUB_OFFLINE=1 speech-to-speech serve \
    --model_name "ggml-org/gemma-4-E4B-it-GGUF" \
    --responses_api_base_url "http://127.0.0.1:8080/v1" \
    --responses_api_api_key ""

หากไม่มีการแทนที่ base URL แบบโลคัล แบ็กเอนด์ LLM responses-api เริ่มต้นจะเรียกใช้บริการระยะไกล อีกทางเลือกหนึ่งคือใช้แบ็กเอนด์โลคัลแบบ in-process เช่น transformers หรือ mlx-lm โมเดลที่เลือกทั้งหมดจะต้องถูกแคชไว้แล้วหรือจัดหาผ่านพาธโลคัลที่รองรับโดยแบ็กเอนด์ของมัน

Smart Turn ใช้ ONNX checkpoint แยกต่างหาก checkpoint ที่แคชไว้จะทำงานร่วมกับ HF_HUB_OFFLINE=1; สำหรับการตั้งค่าที่ชัดเจนและไม่ขึ้นกับแคช ให้ส่ง --smart_turn_model_path /path/to/smart-turn-v3.2-cpu.onnx หาก checkpoint ไม่พร้อมใช้งาน ให้ส่ง --no_smart_turn เพื่อปิดใช้งาน Smart Turn

การรองรับหลายภาษา

การรองรับภาษาขึ้นอยู่กับแบ็กเอนด์ STT และ TTS ที่คุณเลือก ไม่ใช่ตัวไปป์ไลน์เอง:

ส่วนประกอบแบ็กเอนด์ภาษา
STTParakeet TDT (ค่าเริ่มต้น)25 ภาษายุโรป
STTWhisper / Whisper MLX / Faster Whisperครอบคลุมหลายภาษาอย่างกว้างขวาง ขึ้นอยู่กับ Whisper checkpoint ที่เลือก
STTParaformerขึ้นอยู่กับ FunASR checkpoint ที่เลือก; ค่าเริ่มต้นเน้นภาษาจีน
TTSQwen3-TTS (ค่าเริ่มต้น)หลายภาษา โดยมี --qwen3_tts_language auto เป็นค่าเริ่มต้น
TTSKokoroการแมปภาษา/เสียงหลายแบบ ขึ้นอยู่กับความพร้อมใช้งานของแบ็กเอนด์
TTSChatTTSภาษาอังกฤษและจีน
TTSMMS TTSครอบคลุมหลายภาษาอย่างกว้างขวางผ่าน MMS checkpoints

ตรวจสอบให้แน่ใจว่า STT, LLM และ TTS ที่คุณจับคู่รองรับภาษาเป้าหมายของคุณทั้งหมด รูปแบบการใช้งานสองแบบ:

  • ภาษาเดียว: ตั้งค่า --language เป็นรหัสภาษาเป้าหมาย ค่าเริ่มต้นคือ en
  • การสลับภาษา: ตั้งค่า --language auto STT จะตรวจจับภาษาของแต่ละข้อความเสียงที่พูดและส่งต่อไปยัง LLM คุณสามารถเพิ่ม --enable_lang_prompt เพื่อเพิ่มคำสั่ง "Please reply to my message in ..." ได้ ค่าเริ่มต้นคือ False; LLM ขนาดใหญ่มักจะอนุมานภาษาจากบริบท แต่คำสั่งที่ชัดเจนสามารถช่วยโมเดลขนาดเล็กได้

การตรวจจับภาษาอัตโนมัติ:

bash
speech-to-speech serve \
    --stt parakeet-tdt \
    --language auto \
    --llm_backend mlx-lm \
    --model_name "mlx-community/Qwen3-4B-Instruct-2507-bf16"

ภาษาเดียวที่ไม่ใช่ภาษาอังกฤษ ในตัวอย่างนี้คือภาษาจีน:

bash
speech-to-speech serve \
    --stt whisper-mlx \
    --stt_model_name large-v3 \
    --language zh \
    --llm_backend mlx-lm \
    --model_name mlx-community/Qwen3-4B-Instruct-2507-bf16

ทั้งสองคำสั่งยังทำงานร่วมกับ --mac-optimal-settings; แฟล็ก --stt ที่ชัดเจนจะแทนที่ค่าเริ่มต้นที่ตั้งไว้

Pocket TTS

Pocket TTS จาก Kyutai Labs ให้บริการ TTS แบบสตรีมมิ่งพร้อมการโคลนเสียง:

bash
speech-to-speech serve \
    --tts pocket \
    --pocket_tts_voice jean \
    --pocket_tts_device cpu

พรีเซ็ตเสียงที่มีให้: alba, marius, javert, jean, fantine, cosette, eponine, azelma ไฟล์เสียงที่กำหนดเองและพาธ Hugging Face ก็ใช้งานได้เช่นกัน

การอ้างอิง CLI

การอ้างอิงสำหรับอาร์กิวเมนต์ CLI ของไปป์ไลน์อยู่ใน คลาสอาร์กิวเมนต์ และใน speech-to-speech serve -h อาร์กิวเมนต์ของไคลเอนต์จะแสดงโดย speech-to-speech talk -h

พารามิเตอร์ระดับโมดูล

ดู ModuleArguments ซึ่งอนุญาตให้ตั้งค่า:

  • --device ทั่วไป หากทุกส่วนควรทำงานบนอุปกรณ์เดียวกัน
  • ค่าเริ่มต้นของโมเดล/อุปกรณ์ macOS (--mac-optimal-settings)
  • การใช้งาน STT (--stt)
  • แบ็กเอนด์ LLM (--llm_backend: transformers, mlx-lm, responses-api, หรือ chat-completions)
  • การใช้งาน TTS (--tts)
  • ระดับการบันทึก (logging level)
  • ขนาดพูลของไปป์ไลน์เรียลไทม์ (--num_pipelines)

พารามิเตอร์ VAD

ดู VADHandlerArguments ตัวเลือกที่น่าสนใจ:

  • --thresh: ค่าเกณฑ์เพื่อกระตุ้นการตรวจจับกิจกรรมเสียง (VAD)
  • --min_speech_ms: ระยะเวลาขั้นต่ำของกิจกรรมเสียงที่ตรวจพบเพื่อพิจารณาว่าเป็นคำพูด
  • --min_speech_continuation_ms: เกณฑ์ hysteresis ของแถบ sustain สำหรับคำพูดที่ต่อเนื่องจากเทิร์นที่จบแบบนุ่มนวล, ยังไม่ถูกคอมมิต และสามารถเปิดใหม่ได้ภายในช่วงเวลาที่เปิดใหม่ได้ การจับคู่เริ่มต้นและแนะนำคือ --min_speech_ms 384 --min_speech_continuation_ms 192
  • --min_silence_ms: ความยาวขั้นต่ำของช่วงเวลาเงียบสำหรับการแบ่งส่วนคำพูด ค่าเริ่มต้นคือ 64 มิลลิวินาที
  • --short_segment_merge_ms: หน้าต่างการรวมเสริมสำหรับเชื่อมต่อส่วน VAD ที่อยู่ติดกันซึ่งแต่ละส่วนสั้นกว่า --min_speech_ms
  • --speculative_reopen_ms: หน่วงการคอมมิตการตอบสนองเป็นเวลา 800 มิลลิวินาทีหลังจากเทิร์นที่จบแบบนุ่มนวล เพื่อให้คำพูดที่กลับมาทันทีสามารถเปิดเทิร์นนั้นใหม่ได้
  • --unanswered_reopen_ms: ขีดจำกัดความสมเหตุสมผลว่าเทิร์นที่จบแบบนุ่มนวลและยังไม่ได้รับการตอบสนองจากผู้ช่วยจะยังคงเปิดใหม่ได้นานแค่ไหน เมื่อเปิดใช้งาน Smart Turn ค่านี้จะถูกจำกัดให้มีค่าอย่างน้อยเท่ากับ --smart_turn_max_wait_ms เพื่อให้เทิร์นยังคงเปิดใหม่ได้ตลอดช่วงเวลาผ่อนผัน

การกำหนดจุดสิ้นสุดด้วย Smart Turn

Smart Turn v3.2 สามารถตรวจสอบการตัดสินใจสิ้นสุดคำพูดของ Silero ได้โดยใช้เนื้อหาและทำนองของเทิร์นปัจจุบัน Silero จะสรุปส่วนนั้น และงาน STT/LLM อาจเริ่มต้นแบบคาดการณ์ เทิร์นที่สมบูรณ์จะเริ่มประมวลผลทันทีและใช้ --speculative_reopen_ms (ค่าเริ่มต้น 800 มิลลิวินาที) ก่อนที่จะคอมมิตผลลัพธ์ เทิร์นที่ไม่สมบูรณ์จะรอ --smart_turn_incomplete_delay_ms (ค่าเริ่มต้น 600 มิลลิวินาที) ก่อนที่จะเริ่มงาน STT/LLM ในขณะที่ผลลัพธ์ของพวกเขายังคงถูกควบคุมโดย --smart_turn_max_wait_ms (ค่าเริ่มต้น 2 วินาที) หากคำพูดกลับมาในช่วงเวลาหน่วงใดๆ เทิร์นที่มีอยู่จะถูกเปิดใหม่เป็นเวอร์ชันที่ใหม่กว่า เสียงที่สะสมไว้จะถูกปล่อยออกมาอีกครั้ง และงานจากเวอร์ชันก่อนหน้าจะถูกทิ้งก่อนที่จะถึงผู้ใช้

แพ็กเกจพื้นฐานประกอบด้วยรันไทม์ CPU แบบ quantized และเปิดใช้งาน Smart Turn โดยค่าเริ่มต้น:

bash
pip install speech-to-speech
speech-to-speech serve

เช็คพอยต์ v3.2 CPU ล่าสุดที่รองรับจะถูกดาวน์โหลดจาก Hugging Face Hub เมื่อใช้งานครั้งแรก หากต้องการใช้โมเดลในเครื่อง ให้ส่ง --smart_turn_model_path /path/to/model.onnx หรือใช้ --no_smart_turn เพื่อปิดใช้งาน Smart Turn Smart Turn ถูกเปิดใช้งานโดยค่าเริ่มต้นสำหรับเซสชันเซิร์ฟเวอร์และไคลเอนต์ในเครื่องที่มาพร้อมแพ็กเกจ

ปรับการตัดจบด้วย --smart_turn_threshold (ค่าเริ่มต้น 0.5) ค่าเกณฑ์ที่สูงขึ้นจะทำให้การหยุดชั่วคราวที่คลุมเครือมีแนวโน้มที่จะใช้ช่วงเวลาผ่อนผันการตอบสนองแบบคาดการณ์ที่นานขึ้น

พารามิเตอร์ STT, LLM และ TTS

model_name, torch_dtype และ device ถูกเปิดเผยสำหรับแต่ละการใช้งาน STT, LLM และ TTS พารามิเตอร์ STT และ TTS ใช้คำนำหน้า handler เช่น --stt_model_name หรือ --qwen3_tts_device การเลือกโมเดล LLM และการตั้งค่าแชทจะถูกแชร์ระหว่างแบ็กเอนด์ผ่านแฟล็กที่ไม่มีคำนำหน้า เช่น --model_name และ --chat_size; แฟล็กเฉพาะแบ็กเอนด์จะใช้คำนำหน้า responses_api_ สำหรับแบ็กเอนด์ responses-api และ chat-completions และคำนำหน้า llm_ สำหรับแบ็กเอนด์ในเครื่อง

ตัวอย่างเช่น:

bash
# Local transformers/mlx-lm backend
--model_name google/gemma-2b-it

# OpenAI-compatible backend
--llm_backend responses-api --model_name deepseek-chat --responses_api_base_url https://api.deepseek.com

พารามิเตอร์การสร้าง

พารามิเตอร์การสร้างอื่นๆ สามารถตั้งค่าได้โดยใช้คำนำหน้า handler บวกกับ _gen_ ตัวอย่างเช่น --stt_gen_max_new_tokens 128 หรือ --llm_gen_temperature 0.7 พารามิเตอร์ที่ยังไม่ถูกเปิดเผยสามารถเพิ่มลงในคลาส arguments ที่เกี่ยวข้องได้

การมีส่วนร่วม

ยินดีรับ Issues และ PRs จุดเริ่มต้นที่ดีคือ open issues สำหรับการเปลี่ยนแปลงที่ใหญ่ขึ้น โปรดเปิด issue ก่อนเพื่อหารือเกี่ยวกับแนวทาง

สำหรับการพัฒนาในเครื่อง:

bash
uv sync
pytest
ruff check

ประวัติ Star

Star History Chart

การอ้างอิง

หากคุณใช้ไปป์ไลน์นี้ โปรดอ้างอิงโมเดลส่วนประกอบที่คุณรันด้วย ค่าเริ่มต้นคือ:

Silero VAD

bibtex
@misc{SileroVAD,
  author = {Silero Team},
  title = {Silero VAD: pre-trained enterprise-grade Voice Activity Detector (VAD), Number Detector and Language Classifier},
  year = {2021},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/snakers4/silero-vad}},
  email = {hello@silero.ai}
}

Parakeet TDT

bibtex
@misc{parakeet-tdt,
  author = {NVIDIA},
  title = {Parakeet TDT 0.6B v3},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/nvidia/parakeet-tdt-0.6b-v3}}
}

Qwen3-TTS

bibtex
@misc{qwen3-tts,
  author = {Qwen Team},
  title = {Qwen3-TTS},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice}}
}

การอ้างอิงสำหรับแบ็กเอนด์เสริม เช่น Kokoro, Pocket TTS, ChatTTS, Whisper variants, Paraformer และ MMS อยู่ใน READMEs ของส่วนประกอบ ที่เกี่ยวข้อง

เอกสารโปรเจกต์

อ่านเอกสารต้นฉบับ

README วิธีติดตั้ง วิธีใช้งาน และข้อกำหนดจาก repository ต้นฉบับ

ดูไฟล์บน GitHub

Speech To Speech: Build voice agents with open-source models

GitHub Trending: #1 Repository of the Day

PyPI Python License

A low-latency voice agent built from open models that runs entirely on your computer. One command starts a conversation: no API key, no cloud service.

The default pipeline is Silero VAD → Parakeet TDT → Qwen3.5-4B → Qwen3-TTS, and every stage is swappable. The server speaks the OpenAI Realtime protocol over WebSocket and WebRTC, so apps built for OpenAI's Realtime API can point at your own machine instead.

This pipeline runs in production as the conversation backend for thousands of Reachy Mini robots.

Switching an OpenAI Realtime client endpoint from hosted OpenAI to a self-hosted speech-to-speech server

Quickstart

Use CPython 3.11–3.14 (3.11 recommended):

bash
python3 -m venv .venv
source .venv/bin/activate
pip install speech-to-speech
speech-to-speech local

Then talk: speak, pause, and the assistant answers through your speakers. Stop with Ctrl+C. The first run downloads the models, so give it a few minutes. On speakers, add --echo-cancellation so the assistant does not hear itself and you can still interrupt it by voice; headphones don't need it. See echo cancellation for requirements and limits.

By default, local and talk show final user transcripts and streaming assistant replies once, hiding backend transcript copies, routine logs, tool details, and protocol events. User messages are yellow and assistant replies are green in a color-capable terminal. Startup shows Loading models…, followed by Ready — start speaking. once the audio devices are running and the session is configured. Routine model-loading output is hidden; startup failures show their diagnostics. Runtime warnings and errors remain visible.

For diagnostic output, add --verbose:

bash
speech-to-speech local --verbose

Use --verbose --log_level debug for more detailed local logs. Raw event output (local --local_audio_print_json or talk --print-json) also enables diagnostic output.

On Ubuntu, first install the audio libraries with sudo apt-get install libportaudio2 libsndfile1. The default Linux Qwen3-TTS wheel targets CUDA 12.8 and Ubuntu 24.04; see the CUDA note for other systems. On Windows, activate the environment with .venv\Scripts\Activate.ps1.

The default installation has the following CI coverage:

PlatformSupported CPython versionsChecks
Linux3.11, 3.12, 3.13, 3.14Full test suite and installed package smoke test
Apple Silicon macOS3.11, 3.12, 3.13, 3.14Installed package smoke test

Optional model backends can have narrower Python requirements. Windows is not covered by this compatibility matrix. Python 3.10 is no longer supported following its end of life on October 1, 2026.

Kokoro is optional on every platform. On macOS, its Misaki dependency requires Python <3.13, so use Python 3.11 or 3.12 with speech-to-speech[kokoro]. The default Qwen3-TTS backend does not require Misaki. Python 3.15 is not yet supported on any platform: ONNX Runtime lacks CPython 3.15 wheels, and the pinned macOS PyTorch release also lacks them. Newer Python versions will be added after the default dependencies and CI checks pass; the package's requires-python lower bound does not promise compatibility with future Python releases.

The command picks local models for your platform:

PlatformLLMPlan for
Apple Silicon MacQwen3.5-4B 4-bit via MLX LM16 GB of unified memory
Linux / Windows with NVIDIAQwen3.5-4B via Transformers24 GB of VRAM
Other machinesQwen3.5-4B via Transformers on CPUSlow replies

Speech recognition and synthesis run locally too. After the first run, everything works offline. To use another model, a llama.cpp server, or a hosted provider, see LLM backends.

Connect your own app

local runs a server and a microphone client in one process. To run only the server:

bash
speech-to-speech serve

It listens at ws://127.0.0.1:8765/v1/realtime. Connect with:

  • the packaged audio client: speech-to-speech talk --url ws://127.0.0.1:8765/v1/realtime
  • the browser demo
  • the optional Open WebUI local example, for saved text/voice chat with typed context updates during a call
  • any client using the core OpenAI Realtime events; the OpenAI Agents SDK is tested over both transports (see Realtime API)
  • LiveKit Agents, as the agent's realtime model

Index

How it works

The pipeline is a cascade of four components, each running in its own thread and connected by queues:

  1. 1Voice Activity Detection (VAD): Silero VAD detects speech boundaries and turn-taking.
  2. 2Speech to Text (STT): transcribes the user's turn, with optional live partial transcripts.
  3. 3Language Model (LLM): generates the response, streaming text and tool calls.
  4. 4Text to Speech (TTS): synthesizes audio and streams it back to the client.

Every stage has multiple interchangeable backends, selected via CLI flags. The code is designed for easy modification, with a focus on models available through Transformers and the Hugging Face Hub.

Optional speech-to-viseme extraction adds timed mouth shapes for avatar and robot clients after TTS. Enable it with --enable_visemes; see the viseme guide for client events and timing.

Installation

pip install speech-to-speech (see the Quickstart) includes everything the default pipeline needs:

  • Silero VAD and Parakeet TDT for listening
  • Qwen3.5-4B for replies: MLX LM on macOS, Transformers elsewhere
  • Qwen3-TTS for speech: mlx-audio on Apple Silicon, GGML elsewhere
  • the local audio client and the Realtime server

Platform-specific dependencies are resolved automatically.

See the configuration guide for reusable blocks, named pipelines, environment references, and explicit Python startup. The Mac example runs fully locally on Apple Silicon. From a repository checkout, run its audio client and server together, or start only the server:

bash
speech-to-speech local -f example_configs/mac.yaml
speech-to-speech serve -f example_configs/mac.yaml --name mac

local runs one selected pipeline with the packaged loopback audio client. talk -f example_configs/mac.yaml uses only the file's client settings. Configured server startup currently supports one named definition per invocation; its num_pipelines controls the number of isolated instances. Existing Python interfaces, CLI commands, and flat JSON configuration remain available.

CUDA Note for Qwen3-TTS

On Linux, the Qwen3-TTS GGML backend comes from faster-qwen3-tts[ggml]. Its default qwentts-cpp-python wheel on PyPI targets CUDA 12.8 and manylinux_2_39 (for example, Ubuntu 24.04). If your CUDA runtime or glibc is older, install the matching wheel from the Hugging Face wheelhouse before installing speech-to-speech:

bash
# CUDA 13.x
pip install "qwentts-cpp-python==0.3.1+cu130" \
  -f https://huggingface.co/datasets/andito/qwentts-cpp-python-wheels/tree/main/whl/cu130

# CUDA 12.4
pip install "qwentts-cpp-python==0.3.1+cu124" \
  -f https://huggingface.co/datasets/andito/qwentts-cpp-python-wheels/tree/main/whl/cu124

# CPU-only fallback
pip install "qwentts-cpp-python==0.3.1+cpu" \
  -f https://huggingface.co/datasets/andito/qwentts-cpp-python-wheels/tree/main/whl/cpu

pip install speech-to-speech

On DGX Spark (Linux ARM64, CUDA 13), the default CUDA 12 wheel can fail with libcudart.so.12 missing. From the repository root, sync dependencies, then install the CUDA 13 ARM64 wheel and launch with --no-sync as shown below. Plain uv run or uv sync can replace this wheel; reinstall it after syncing.

bash
uv sync
uv pip install --python .venv/bin/python --no-deps \
  "https://huggingface.co/datasets/andito/qwentts-cpp-python-wheels/resolve/main/whl/cu130/qwentts_cpp_python-0.5.0%2Bcu130-py3-none-manylinux_2_39_aarch64.whl"
uv run --no-sync speech-to-speech serve

To use the previous CUDA-graphs implementation instead of GGML, pass --qwen3_tts_backend torch.

Optional Components

Optional components are installed with pip extras:

bash
pip install "speech-to-speech[kokoro]"          # Kokoro-82M TTS (macOS: Python 3.11–3.12)
pip install "speech-to-speech[kitten]"          # KittenTTS
pip install "speech-to-speech[pocket]"          # Pocket TTS
pip install "speech-to-speech[phonon]"          # Phonon TTS (checkpoint supplied separately)
pip install "speech-to-speech[chattts]"         # ChatTTS
pip install "speech-to-speech[omnivoice]"       # OmniVoice TTS (CUDA, Intel XPU, or Apple Silicon)
pip install "speech-to-speech[faster-whisper]"  # Faster Whisper STT
pip install "speech-to-speech[whisper-mlx]"     # Lightning Whisper MLX STT on macOS
pip install "speech-to-speech[paraformer]"      # Paraformer STT through FunASR
pip install "speech-to-speech[fireredvad]"      # FireRed streaming VAD
pip install "speech-to-speech[nemo]"            # Parakeet Unified, Nemotron, and Orukeet STT through NeMo
pip install "speech-to-speech[mlx-lm]"          # mlx-vlm support for vision models on macOS

Deprecated implementations, including MeloTTS, live in archive/ and are no longer wired into the CLI.

Note on DeepFilterNet: DeepFilterNet, used for optional audio enhancement in VAD, requires numpy<2 and conflicts with Pocket TTS, which requires numpy>=2. Install it manually only in environments where you are not using Pocket TTS.

From Source

To work on the code, install Git and uv, then run:

bash
git clone https://github.com/huggingface/speech-to-speech.git
cd speech-to-speech
uv sync --python 3.11
source .venv/bin/activate

This installs the package in editable mode. With the environment activated, use the same speech-to-speech commands shown above.

Supported Components

ComponentBackendPlatformsInstall
VADSilero VADallbuilt-in
VADFireRed Stream-VADCUDA / CPUfireredvad
STTParakeet TDT (default)CUDA / CPU through nano-parakeet, Apple Silicon through MLXbuilt-in
STTParakeet UnifiedCUDA / CPUnemo
STTNemotron Speech StreamingCUDA / CPUnemo
STTNemotron Streaming Farsi, selected with --stt nemotron-streaming --nemotron_streaming_model_name mehdi-hf/nemotron-asr-streaming-farsiCUDA / CPUnemo, NeMo >=3.0, Python >=3.11
STTOrukeetCUDA / CPUnemo
STTWhisper through TransformersCUDA / CPUbuilt-in
STTFaster WhisperCUDA / CPUfaster-whisper
STTLightning Whisper MLXApple Siliconwhisper-mlx
STTMLX Audio WhisperApple Siliconbuilt-in on macOS
STTParaformerCUDA / CPUparaformer
STTQwen3-ASR through TransformersCUDA / CPU, Apple Siliconbuilt-in
STTOpenAI-compatible /v1/audio/transcriptions endpointlocal or remote HTTP serverbuilt-in
STTOpenAI Realtime transcriptionhosted or compatible WebSocket serverbuilt-in
STTvLLM Realtime transcription (experimental)local or remote vLLM serverbuilt-in
LLMmlx-lm (default on macOS)Apple Siliconbuilt-in on macOS
LLMTransformers (default elsewhere)supported accelerators / CPUbuilt-in
LLMOpenAI-compatible API (responses-api, chat-completions)optional hosted providers or self-hosted serversbuilt-in
TTSQwen3-TTS (default)GGML / CUDA on Linux, mlx-audio on macOSbuilt-in
TTSKokoro-82MCUDA / CPU, Apple Siliconkokoro (macOS: Python 3.11–3.12)
TTSKittenTTSCPUkitten
TTSPocket TTSCPU / CUDApocket
TTSPhononCPU (including Apple Silicon)phonon
TTSChatTTSCUDA / CPUchattts
TTSOmniVoiceCUDA / Intel XPU / Apple Siliconomnivoice
TTSIrodori-TTS (--tts irodori)CUDA / Intel XPU / Apple Silicon / CPUinstalled from source
TTSMMS TTSCUDA / CPUbuilt-in
TTSOpenAI-compatible /v1/audio/speech endpointlocal or remote HTTP serverbuilt-in
TTSFish Audio Drama-3 (--tts drama3)SGLang Omni on a local or remote GPU hostbuilt-in client
TTSMiniMaxhosted HTTP streamingbuilt-in

Optional streaming speaker diarization adds speaker labels to transcribed turns. Enable it with --diarization after installing the supporting Transformers build; the linked guide has the current model revision and setup while the merged Transformers PR #49056 is awaiting a package release.

Select implementations with --stt, --llm_backend, and --tts. The CLI constructs configuration only for the selected backends; known options for inactive backends remain accepted for compatibility but are ignored with a warning. JSON configuration may likewise include extra inactive-backend keys, which are ignored. Run speech-to-speech serve -h for the defaults, or pass selectors before -h to see another combination's backend-specific flags (for example, speech-to-speech serve --stt mlx-audio-whisper -h).

For client-only TTS serving with vLLM-Omni or another compatible server, see OpenAI-compatible TTS.

For client-only speech recognition with vLLM, OpenAI's hosted Transcription API, or another compatible server, see OpenAI-compatible STT. For native incremental audio and partial transcripts, see stateful streaming STT.

Commands

CommandBehaviorUse it when
serveRuns the pipeline server over OpenAI Realtime WebSocket and WebRTC.You are building an app or device against the API.
talk --url <full-realtime-url>Runs the packaged microphone/speaker client.You want to talk to an existing Realtime server.
localComposes serve and talk in-process over loopback.You want to run the server and talk to it from one command.

serve binds to 127.0.0.1 by default; pass --host 0.0.0.0 explicitly for network exposure. local always binds to loopback and connects the same packaged client at ws://127.0.0.1:<port>/v1/realtime.

The command only decides how the server and client run. Where replies are generated is set by --llm_backend, which is local by default for every command.

The packaged local client buffers 196 ms of received audio when using the OpenAI-compatible TTS backend, which absorbs short delivery gaps from HTTP speech inference. Other local backends and talk start playback immediately by default. Use --playback-buffer-ms <milliseconds> to override either default: a larger value resists stuttering but delays the start of each response, while a smaller value starts sooner but is more sensitive to jitter. This setting only controls the packaged Python client's speakers; browser and other Realtime clients manage their own playback buffers.

By default, user speech interrupts the assistant: the server cancels the response and the packaged client drops the audio it has queued. Pass talk --no-interrupt-response or local --local_audio_interrupt_response false to let the reply finish. The microphone stays open and your speech is still transcribed, unlike --block-mic-during-playback, which stops sending microphone audio. talk --vad-threshold <0-1> and local --local_audio_vad_threshold <0-1> set the session VAD threshold; without them the server's --thresh applies. A higher threshold can reduce false triggers in a noisy room, but it cannot tell your voice apart from other people talking nearby. See Interruption Handling for the session fields other clients send.

The packaged client can opt in to local Python tools with talk --tool-module <module> or local --tool-module <module>. The module contract, programmatic API, and web-search examples (Serper, or keyless You.com) are documented in Tool calling design.

Migrating from --mode

--mode is deprecated and will stop working soon. During this migration window, speech-to-speech --mode realtime runs speech-to-speech serve, and speech-to-speech --mode local runs speech-to-speech local; both print a warning. All other mode values have been removed and exit with guidance to use the new commands.

Local Mac

On macOS, local and serve already run all three models through MLX. The optional --mac-optimal-settings preset also makes MPS the default device for supported components. It only sets defaults: explicit --device, component-device flags such as --qwen3_tts_device, and --stt, --llm_backend, --model_name, and --tts all win.

--tts pocket, --tts phonon, --tts kokoro, --tts omnivoice, --tts irodori, and --tts kitten are also valid on macOS.

To compare the MLX quantization variants locally:

bash
python scripts/benchmark_tts.py \
    --handlers qwen3 \
    --iterations 3 \
    --qwen3_mlx_quantizations bf16 4bit 6bit 8bit

Docker

Install the NVIDIA Container Toolkit, then:

bash
docker compose up

The compose file starts a llama.cpp server with Gemma 4 and the Realtime server, exposing ports 8080 and 8765.

Realtime API

The server logs per-response STT, LLM, first TTS audio, and speech-to-audio durations for supported backends, including vLLM-backed STT and TTS. Tool-assisted replies also report total LLM time and the number of model rounds. See the response latency guide for the coverage matrix and measurement boundaries.

Realtime mode supports the OpenAI Realtime protocol over WebSocket and WebRTC, with live transcription and low-latency turn-taking. WebSocket clients connect at /v1/realtime:

python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8765/v1",
    websocket_base_url="ws://localhost:8765/v1",
    api_key="not-needed",
)

with client.realtime.connect(model="local") as conn:
    conn.send(
        {
            "type": "session.update",
            "session": {
                "type": "realtime",
                "instructions": "You are a helpful assistant.",
                "audio": {
                    "input": {
                        "turn_detection": {
                            "type": "server_vad",
                            "interrupt_response": True,
                        }
                    }
                },
            },
        }
    )

    for event in conn:
        print(event.type)

The server implements the core Realtime event set: input_audio_buffer.append, session.update, conversation.item.create, conversation.item.truncate, response.create, and response.cancel inbound; speech start/stop, streaming transcription, audio deltas, tool calls, and response.done outbound. CI connects pinned @openai/agents RealtimeSession instances through the SDK's stock WebSocket and WebRTC transports. This is a tested core subset, not a claim of full OpenAI Realtime API equivalence. The event matrix, architecture, and design details live in the Realtime Engine README.

LLM Proxy

With --enable_llm_proxy, the realtime server also exposes the remote LLM it is configured with as a plain OpenAI compatible endpoint, so a client can run side tasks (summaries, titles, background agents) with tools and streaming, fully concurrent with the voice conversation and never interrupted by new speech:

  • POST /v1/chat/completions when running --llm_backend chat-completions
  • POST /v1/responses when running --llm_backend responses-api

The server performs no authentication and no throttling of its own. Enable the proxy only on a trusted network, or deploy the server behind a gateway that owns access control. The s2s-endpoint compute replica is such a gateway: it opens these paths only to clients that created their session with an HF token, checks the API key against that token, and applies a rate limit per user. Point the stock OpenAI SDK at whichever host you talk to; this server ignores the API key (a gateway in front decides what it must be):

python
from openai import OpenAI

llm = OpenAI(base_url="http://localhost:8765/v1", api_key="unused")
completion = llm.chat.completions.create(
    model="anything",  # ignored: the server forces its configured --model_name
    messages=[{"role": "user", "content": "Summarize the conversation so far: ..."}],
)

Requests are stateless (send the full message list each time) and are proxied to the configured upstream with the key held by the server, which never reaches clients. The model field is always overwritten with the server configured --model_name. The proxy is off by default, requires a remote backend (chat-completions or responses-api), and answers 501 with the reason otherwise.

LLM Backends

By default the LLM runs inside the speech process. You can swap the model, run it in a separate server, or hand it to a hosted provider:

Where the LLM runsBackend
In process on Apple Silicon (default)mlx-lm
In process elsewhere (default)transformers
A separate server on your hardware (llama.cpp, vLLM, ...)responses-api or chat-completions
A hosted providerresponses-api or chat-completions

Changing the local model

Pass --model_name, using an MLX conversion on Mac and a Transformers checkpoint elsewhere:

bash
speech-to-speech local --model_name mlx-community/Qwen3.5-9B-4bit   # Apple Silicon
speech-to-speech local --model_name Qwen/Qwen3.5-9B                 # Linux / Windows

Transformers picks an available accelerator and falls back to CPU. --llm_device overrides the LLM's device; --device overrides every stage. Generation options such as --llm_gen_max_new_tokens are in the LLM guide.

Combining with llama.cpp

Serve the LLM with llama.cpp and connect speech-to-speech through its local Responses API. This works on Apple Silicon or Linux/NVIDIA. Install llama.cpp with brew install llama.cpp on macOS or use a CUDA build on NVIDIA.

With the default speech models, budget 24 GB of unified memory on Mac or 16 GB of VRAM on NVIDIA; about 8 GB of that goes to the speech pipeline.

Terminal 1 — start the LLM and leave it running:

bash
llama-server \
    -hf ggml-org/gemma-4-E4B-it-GGUF:Q4_0 \
    --alias local-gemma \
    --host 127.0.0.1 --port 8080 \
    -ngl all -np 1 -c 8192 -fa on \
    --no-mmproj \
    --reasoning off

Terminal 2 — activate your Python environment and connect the speech pipeline to that LLM:

bash
speech-to-speech local \
    --llm_backend responses-api \
    --model_name local-gemma \
    --responses_api_base_url http://127.0.0.1:8080/v1 \
    --responses_api_api_key ""

The Q4_0 weights are about 4.6 GB. The example uses one 8k context and disables reasoning for faster replies; --no-mmproj skips the image/audio projector because STT supplies text. To try another GGUF model, change -hf and keep --alias and --model_name matched.

Local speech with a hosted LLM

Select an API backend to move only the LLM to a provider. For OpenAI:

bash
export OPENAI_API_KEY=...
speech-to-speech local --llm_backend responses-api

This uses gpt-5.6-terra with reasoning effort none. Speech recognition and synthesis stay local, so your audio never leaves your computer; transcribed text and conversation history go to the provider.

Two API backends share the same --responses_api_* connection flags:

  • --llm_backend responses-api targets /v1/responses.
  • --llm_backend chat-completions targets /v1/chat/completions.

Responses API Backend

Works with any provider or server that implements the OpenAI Responses API. Point --responses_api_base_url at the endpoint and set --model_name accordingly:

Provider / server--responses_api_base_url--responses_api_api_key
OpenAIomit, uses OpenAI default$OPENAI_API_KEY
HF Inference Providershttps://router.huggingface.co/v1$HF_TOKEN
OpenRouterhttps://openrouter.ai/api/v1$OPENROUTER_API_KEY
vLLMhttp://localhost:8000/v1omit or any string
llama.cpphttp://127.0.0.1:8080/v1empty string
bash
# OpenAI
speech-to-speech local \
    --llm_backend responses-api \
    --model_name "gpt-6-luna" \
    --responses_api_api_key "$OPENAI_API_KEY" \
    --responses_api_stream \
    --enable_live_transcription
bash
# HF Inference Providers: Qwen3.5-9B via Together
speech-to-speech local \
    --llm_backend responses-api \
    --model_name "Qwen/Qwen3.5-9B:together" \
    --responses_api_base_url "https://router.huggingface.co/v1" \
    --responses_api_api_key "$HF_TOKEN" \
    --responses_api_stream \
    --enable_live_transcription
bash
# HF Inference Providers: GPT-oss-20B via Groq
speech-to-speech serve \
    --llm_backend responses-api \
    --model_name "openai/gpt-oss-20b:groq" \
    --responses_api_base_url "https://router.huggingface.co/v1" \
    --responses_api_api_key "$HF_TOKEN" \
    --responses_api_stream \
    --enable_live_transcription

Chat Completions Backend

Identical configuration to responses-api, reusing the same --responses_api_* connection flags, but talks to /v1/chat/completions instead of /v1/responses. Prefer it when:

  • the provider ignores chat_template_kwargs.enable_thinking on the Responses path and needs a reasoning_effort knob to suppress reasoning, or
  • the server's Responses streaming tool-call path is unreliable, while its Chat Completions tool-call streaming is solid. This is useful for some vLLM builds; see #312.

Add --responses_api_reasoning_effort none to disable reasoning on providers where the chat-template flag has no effect:

bash
# vLLM serving a Qwen model with tool calling
speech-to-speech serve \
    --llm_backend chat-completions \
    --model_name "Qwen/Qwen3.5-4B" \
    --responses_api_base_url "http://localhost:8000/v1" \
    --responses_api_stream
bash
# Gemma 4 31B via the HF router on Cerebras, with reasoning disabled for low voice latency
speech-to-speech serve \
    --llm_backend chat-completions \
    --model_name "google/gemma-4-31B-it:cerebras" \
    --responses_api_base_url "https://router.huggingface.co/v1" \
    --responses_api_api_key "$HF_TOKEN" \
    --responses_api_reasoning_effort none \
    --responses_api_stream

Direct Audio Input (No STT)

Use --stt none --llm_backend chat-completions to send each completed VAD audio segment directly to an audio-input model. Direct audio mode is not supported with --llm_backend responses-api: a model may accept audio through /v1/chat/completions without supporting /v1/responses, including OpenAI's gpt-audio-1.5.

You must explicitly set --model_name to a model that accepts audio: the API backends' default gpt-5.6-terra accepts text and image input, but not audio. Check the provider's model documentation and endpoint support before enabling this mode. For OpenAI, see the GPT-5.6 Terra model card and audio-input guide.

bash
speech-to-speech serve \
    --stt none \
    --llm_backend chat-completions \
    --model_name "YOUR_AUDIO_CAPABLE_MODEL" \
    --responses_api_base_url "https://provider.example/v1" \
    --responses_api_api_key "$PROVIDER_API_KEY"

OpenAI-compatible servers represent input audio differently. Use --responses_api_audio_content_type input_audio (the default) for embedded WAV base64, or --responses_api_audio_content_type audio_url for a base64 data URL.

For a fully local audio-input model on Apple Silicon, see the Gemma 4 12B example.

Offline Operation

The pipeline can run without internet access after the dependencies and model assets for the selected components are installed locally. Before disconnecting, start the exact configuration once while online so it can cache the STT, LLM, TTS, Silero VAD, NLTK, and Smart Turn resources it needs.

After that first run, set HF_HUB_OFFLINE=1 to skip Hugging Face Hub requests:

bash
HF_HUB_OFFLINE=1 speech-to-speech local

For the llama.cpp configuration, keep the LLM server running and pass the same LLM flags:

bash
HF_HUB_OFFLINE=1 speech-to-speech serve \
    --llm_backend responses-api \
    --model_name local-gemma \
    --responses_api_base_url "http://127.0.0.1:8080/v1" \
    --responses_api_api_key ""

Hosted LLMs still need a connection.

Smart Turn uses a separate ONNX checkpoint. A cached checkpoint works with HF_HUB_OFFLINE=1; for an explicit, cache-independent setup, pass --smart_turn_model_path /path/to/smart-turn-v3.2-cpu.onnx. If the checkpoint is not available, pass --no_smart_turn to disable Smart Turn.

Multi-Language Support

Language coverage depends on the STT and TTS backends you pick, not on the pipeline itself:

ComponentBackendLanguages
STTParakeet TDT (default)25 European languages
STTWhisper / Whisper MLX / Faster WhisperBroad multilingual coverage, depending on the selected Whisper checkpoint
STTParaformerDepends on the selected FunASR checkpoint; the default is Chinese-oriented
TTSQwen3-TTS (default)Multilingual, with --qwen3_tts_language auto by default
TTSKokoroMultiple language/voice mappings, depending on backend availability
TTSKittenTTSEnglish
TTSChatTTSEnglish and Chinese
TTSMMS TTSBroad multilingual coverage through MMS checkpoints
TTSOmniVoice600+ languages; voice cloning, design, and automatic voice selection
TTSIrodori-TTSJapanese; voice design and voice cloning
TTSSupertonic32 languages
TTSPocket TTSEnglish, French, German, Portuguese, Italian, Spanish
TTSOpenAI-compatible /v1/audio/speech endpointDepends on the connected TTS server/model

Make sure the STT, LLM, and TTS you pair all cover your target language(s). By default, the language code sent to TTS comes from the user's transcription. Qwen3-TTS keeps its configured auto behavior by default. Add --detect_llm_output_language to detect the language of each assistant text chunk instead and send that code to TTS. This helps when the assistant replies in a different language from the user. The Lingua detector is loaded and warmed when the pipeline starts, so detection does not wait for the full reply. Short text (under 20 characters for most languages, or under four CJK characters) and ambiguous text use the last detected assistant language for that response. If there is none yet, TTS receives no language code and uses its own automatic or default behavior; this avoids delaying speech to collect more text. A TTS backend must support the detected language to use it. When a Realtime session selects a language with session.audio.input.transcription.language, STT keeps that language, but TTS receives the confidently detected assistant language instead. The first spoken text of each response decides; if it is too short or ambiguous, the whole response uses the session's selected language. If the active TTS backend cannot speak the detected language, that response uses the session's selected language.

For Parakeet TDT, the decoder chooses the transcription language automatically. --parakeet_tdt_language remains accepted for compatibility with existing commands, but setting it to a code such as de does not constrain decoding. The reported language is inferred with Lingua from the finished transcription when possible. Text shorter than 20 characters is not classified, and inconclusive or failed detection reports an unknown language rather than the configured or previous code. --language belongs to the Whisper backends; it does not control Parakeet. For Whisper and Whisper MLX, use --language auto to detect each turn, or a code such as --language zh to fix the language. Other STT backends have their own language flags; see the STT component guide.

To encourage replies in the user's detected language, add --enable_lang_prompt. It appends a per-turn instruction such as "Please reply to my message in French." The flag is off by default and works independently of --detect_llm_output_language. Qwen3-TTS uses --qwen3_tts_language auto by default: it infers language from text unless assistant language detection or a session selection supplies a supported code. Set --qwen3_tts_language german, for example, to force synthesis in German.

Automatic detection with Parakeet and a language instruction for the LLM:

bash
speech-to-speech serve \
    --stt parakeet-tdt \
    --enable_lang_prompt \
    --detect_llm_output_language \
    --qwen3_tts_language auto

A single non-English language, Chinese in this example:

bash
speech-to-speech serve \
    --stt whisper-mlx \
    --stt_model_name large-v3 \
    --language zh

Both commands also work with --mac-optimal-settings; explicit --stt flags override the defaults it sets.

OmniVoice

OmniVoice provides voice cloning, voice design, and automatic voice selection across 600+ languages. Install its opt-in dependencies and provide a reference clip plus its transcript for voice cloning. This example uses CUDA on Linux or Windows; use --omnivoice_device mps on Apple Silicon, --omnivoice_device xpu with an Intel XPU-enabled PyTorch installation, or --omnivoice_device npu with an Ascend torch_npu installation:

bash
pip install "speech-to-speech[omnivoice]"
speech-to-speech serve \
    --tts omnivoice \
    --omnivoice_device cuda \
    --omnivoice_ref_audio /path/to/reference.wav \
    --omnivoice_ref_text "Transcript of the reference clip."

The handler converts OmniVoice's completed 24 kHz float output into the pipeline's 16 kHz int16 blocks. OmniVoice does not currently expose incremental audio through generate(), so the first block is available only after the full utterance has been synthesized. See the TTS component guide for saved prompts, voice design, devices, latency, and all backend flags.

The omnivoice extra is supported on Linux, Windows, and macOS. On non-macOS platforms, both OmniVoice and the built-in Qwen3 backend share Transformers 5 through faster-qwen3-tts>=0.4.0, so installing this extra keeps the default Qwen3 path available. Linux uses Qwen3's GGML extra by default; see the CUDA note if its CUDA 12.8 / manylinux_2_39 native wheel does not match your host.

คำเตือน

OmniVoice's code is Apache-2.0, but its pretrained weights are CC-BY-NC and are not licensed for commercial use. Use voice cloning only with authorization and consent; do not use it for impersonation, fraud, scams, or other illegal or unethical activity.

Irodori-TTS

Irodori-TTS is a Japanese flow-matching model. A voice is described in a sentence, cloned from a reference clip, or both. The default checkpoint, Irodori-TTS-v4.1-Small-MF, samples in four steps.

Irodori-TTS and its DACVAE codec are not on PyPI, so there is no extra. Install these inspected commits after speech-to-speech:

bash
pip install --no-deps \
    "irodori-tts @ git+https://github.com/Aratako/Irodori-TTS@382205679ebc32295b7d1bfb329327d04c8f4eed" \
    "dacvae @ git+https://github.com/facebookresearch/dacvae@414c20785fc3a28373073ea8ef7a1316eeeaca6e" \
    "descript-audiotools==0.7.2"
pip install einops ffmpy flatten-dict importlib-resources julius pyloudnorm randomname tensorboard torchcodec
speech-to-speech serve \
    --tts irodori \
    --irodori_caption "落ち着いた低い声の男性。ゆっくりと丁寧に話す。"

Keep --no-deps: descript-audiotools declares protobuf<3.20, which would downgrade the installed protobuf, and Irodori-TTS lists its training and demo stack as requirements. The second command installs what inference imports.

Irodori-TTS speaks Japanese only, so pair it with an STT backend that recognizes Japanese and an LLM that answers in Japanese; see Multi-language support. See the TTS component guide for voice cloning, devices, latency, and limits.

คำเตือน

Irodori-TTS code and weights are MIT, with ethical restrictions in the model card. Clone a voice only with the speaker's consent; do not use it for impersonation or to mislead.

Pocket TTS

Pocket TTS from Kyutai Labs provides streaming TTS with voice cloning:

bash
speech-to-speech serve \
    --tts pocket \
    --pocket_tts_voice jean \
    --pocket_tts_device cpu

Available voice presets: alba, marius, javert, jean, fantine, cosette, eponine, azelma. Custom voice files and Hugging Face paths also work.

Pocket TTS Farsi v2

Select mehdi-hf/pocket-tts-farsi-v2 with --pocket_tts_model_name. The handler normalizes Persian spelling, expands numbers, and converts assistant text to phonemes with mehdi-hf/Homo-GE2PE-Persian-HF before synthesis. Both models download on first use.

The released Pocket TTS package does not support this model's phoneme frontend flags yet. Install the author's fork after the pocket extra. This command pins an inspected commit for reproducibility:

bash
pip install "speech-to-speech[pocket]"
pip install "pocket-tts @ git+https://github.com/mallahyari/pocket-tts@3807c204babb5fe54be8fe18a362a58315e870d6"
speech-to-speech serve \
    --tts pocket \
    --pocket_tts_model_name mehdi-hf/pocket-tts-farsi-v2 \
    --pocket_tts_voice /voices/persian-reference.wav \
    --pocket_tts_device cpu

Use a Persian reference recording as a local audio file or Hugging Face audio URL. Preset voice states such as jean are incompatible with these weights. The handler uses the first five seconds of the recording. It splits text at sentence boundaries before phoneme conversion, adds a 0.25-second pause between sentences, and limits synthesis chunks to 18 tokens. It keeps ezafe-linked words together and rejects a linked phrase that exceeds the budget. Oversized G2P inputs raise an error rather than lose text. Configure the LLM to respond in Persian. This model choice stays fixed for the session and does not switch languages based on STT detection.

Farsi synthesis bypasses the fork's orthographic sentence splitter so that ? remains a glottal-stop phoneme. It uses an EOS threshold of -2 and zero extra frames after EOS. --pocket_tts_temperature overrides the model's default of 0.3; --pocket_tts_eos_threshold overrides -2. Each phoneme chunk is buffered before playback. Silent, non-finite, or length-capped output is retried once, then reported as an error. This adds one chunk's generation time before the first audio block, but avoids playing a failed attempt. PCM conversion clips peaks instead of wrapping, and downsampling preserves filter history across playback blocks.

To check the handler with actual weights from a source checkout, run:

bash
python scripts/check_pocket_tts_farsi.py --output-dir /tmp/pocket-tts-farsi-check

The check downloads the TTS and G2P models and the author's Persian reference samples/prompt_short_sentence.wav. It uses seed 42 and temperature 0.3. It synthesizes a greeting, a sentence with a Persian number, and a two-sentence reply. It checks PCM block format, non-silent output, and response completion, then saves WAVs and timing measurements. Listen to the WAVs to assess pronunciation. Use --voice /voices/reference.wav to test your own recording. The check saves native 24 kHz audio by default. Pass --sample-rate 16000 to compare with the pipeline's current 16 kHz playback output. The server and local playback path still assume 16 kHz, so changing only --pocket_tts_sample_rate to 24000 does not enable native-rate playback.

The model weights use CC-BY-NC-4.0 and are for non-commercial use.

Phonon TTS

Phonon from Gradium streams speech locally through the Rust-backed ptts Python runtime. Install the optional extra:

bash
pip install "speech-to-speech[phonon]"
speech-to-speech local --mac-optimal-settings --tts phonon

The default checkpoint is gradium/phonon-31m-en, a public English model under Apache-2.0. It downloads on first use without a Hugging Face login. --phonon_tts_model_name accepts another Hub repo or a local checkpoint directory, which must include its matching config.json, tokenizer.json, q8 model.q8.gguf, and voice embeddings. Besides the checkpoint's own voices, Phonon offers the Phonon voice catalog voices in the checkpoint's languages (37 for English). A catalog voice downloads on first use. Use --phonon_tts_voice VOICE_NAME to select one; omitting it uses the checkpoint's default. Keep private checkpoints outside the repository.

local --tts phonon lets you cycle through these voices using the terminal's left/right or up/down arrows. The selected voice is displayed immediately and applied after the current reply finishes, preserving the conversation. This requires an interactive macOS or Linux terminal. The standalone talk client can opt in with --voices Zoey Harper Easton and select its initial voice with --voice Zoey.

Phonon uses four native CPU threads by default, which performed better than the runtime's twelve-thread default on an Apple M3 Pro in local testing. Use --phonon_tts_num_threads N to tune it at startup; the setting is shared by all Phonon pipelines in the process.

Phonon ends each utterance with a long quiet tail, which adds a pause between sentence-streamed chunks. --phonon_tts_max_trailing_silence_ms 120 shortens that tail toward a 120 ms target (minimum setting 40); omitting it, the default, preserves native audio. Audio below -60 dBFS RMS in 10 ms windows counts as quiet. Leading audio and internal pauses are kept. At most one second is removed per utterance, so a tail more than one second over the target stays longer than it. Speech is not delayed: only quiet audio beyond the target is held, until speech resumes or the utterance ends. Very quiet voices may need native audio.

Phonon runs on CPU even when STT or the LLM uses a GPU. Native audio is resampled to the pipeline's 16 kHz PCM16 output, and interruption closes the native stream. --phonon_tts_language fixes text normalization at startup; use en (the default), fr, de, es, pt, or none. Session language changes are restricted to that configured language. See the TTS component guide for installation and checkpoint options.

The Phonon 40M checkpoints, such as gradium/phonon-40m-en, are gated and use CC BY-NC 4.0, so they are for non-commercial use. To use one, accept its terms on Hugging Face, set HF_TOKEN or run hf auth login, and pass --phonon_tts_model_name gradium/phonon-40m-en.

CLI Reference

References for pipeline CLI arguments live in the arguments classes and in speech-to-speech serve -h. Client arguments are listed by speech-to-speech talk -h.

Module-Level Parameters

See ModuleArguments. It allows setting:

  • a common --device, if every part should run on the same device
  • macOS model/device defaults (--mac-optimal-settings)
  • STT implementation (--stt)
  • LLM backend (--llm_backend: transformers, mlx-lm, responses-api, or chat-completions)
  • TTS implementation (--tts)
  • logging level
  • transcript logging (--log_transcripts)
  • realtime pipeline pool size (--num_pipelines)
  • PyTorch CPU thread count (--torch_num_threads)

Logs are content-free by default: transcript-bearing records report a character count rather than the text, because logs are commonly retained by service managers, containers and hosted log aggregators. Pass --log_transcripts to include full user and assistant transcripts when debugging STT, LLM, TTS or Realtime behaviour; it logs a warning at startup because enabling it writes conversation content wherever those logs are collected. The talk client takes the same flag, as --log-transcripts or --log_transcripts.

--torch_num_threads N sets PyTorch's CPU intra-op thread count (torch.set_num_threads) for the whole process. It is unset by default, which keeps the current behaviour: Silero VAD sets PyTorch to a single thread when it loads, and that single thread also applies to every other PyTorch model on the CPU. If your STT runs on the CPU, you can trade some Silero speed for faster transcription:

bash
speech-to-speech serve --stt parakeet-tdt --device cpu --torch_num_threads 8

The setting is shared: Silero and the CPU STT use the same thread count, and more threads can slow Silero down, so measure the complete pipeline when choosing a value. It only affects PyTorch; ONNX Runtime, MLX and other non-PyTorch backends keep their own thread settings. In a YAML configuration, set it under runtime as torch_num_threads. See the torch.set_num_threads documentation.

VAD Parameters

See VADHandlerArguments. Notable options:

  • --thresh: threshold value to trigger voice activity detection.
  • --min_speech_ms: minimum duration of detected voice activity to be considered speech (default 384 ms).
  • --barge_in_ms: optional override for --min_speech_ms while the assistant is speaking (including buffered playback) to interrupt it; 0 (default) keeps --min_speech_ms.
  • --barge_in_min_confident_speech_ms: optional override for --min_confident_speech_ms while the assistant is speaking (including buffered playback); requires --min_confident_speech_ms > 0; 0 (default) keeps --min_confident_speech_ms.
  • --min_speech_continuation_ms: sustain-bar hysteresis threshold for speech that continues a reopenable soft-ended, uncommitted turn within the reopen window. The default and recommended pairing is --min_speech_ms 384 --min_speech_continuation_ms 192.
  • --min_silence_ms: minimum length of silence intervals for segmenting speech. Default is 64 ms.
  • --short_segment_merge_ms: optional merge window for stitching adjacent VAD segments that are each shorter than --min_speech_ms.
  • --speculative_reopen_ms: delay response commitment for 800 ms after a soft-ended turn so immediately resumed speech can reopen it.
  • --unanswered_reopen_ms: sanity cap on how long a soft-ended speculative turn that has not yet received any assistant output stays reopenable. With Smart Turn enabled, this is clamped to at least --smart_turn_max_wait_ms so a turn remains reopenable for its full grace.

Smart Turn endpointing

Smart Turn v3.2 can validate Silero's end-of-speech decisions using the content and prosody of the current turn. Silero finalizes the segment and STT/LLM work may begin speculatively. Complete turns start processing immediately and use --speculative_reopen_ms (800 ms by default) before committing output. Incomplete turns wait --smart_turn_incomplete_delay_ms (600 ms by default) before starting STT/LLM work, while their output remains gated by --smart_turn_max_wait_ms (2 seconds by default). If speech resumes during either delay, the existing turn is reopened as a newer revision, the accumulated audio is re-emitted, and work from the previous revision is discarded before it reaches the user.

The turn tracker owns the conversation order and the LISTENING, SOFT_ENDED, ANSWERING, and CLOSED states. VAD supplies speech boundaries and Smart Turn timing; the tracker decides whether resumed speech reopens the current turn. The unanswered reopen cap uses streamed-audio time, so a push-to-talk pause with no audio does not advance it. Processing and output holds use wall-clock deadlines. Starting a newer turn drops older work that has not committed; accepted output can finish.

Each response belongs to the input supplied to generation. The server records that ownership on conversation items and accepted tool calls. A tool follow-up keeps its originating input's turn. If a user message follows the tool call, the follow-up answers that message's turn; if a newer turn closed without one, it moves to that turn, so a late tool result is still spoken. Client input without a speech-turn association stays untagged. A response cannot borrow the identity of speech still being recorded. These input records do not control turn state, reopening, or deadlines.

The server holds input_audio_buffer.speech_stopped and the final transcription while a turn can still reopen. Resumed speech keeps the same open item and live transcription deltas continue. Once the turn commits, the client receives one stop, an input-buffer commitment, the created user item, and one final transcript, so its user-turn history matches the model's. If transcription fails, the server sends the stop and failure after the reopen grace ends.

The base package includes the quantized CPU runtime and enables Smart Turn by default:

bash
pip install speech-to-speech
speech-to-speech serve

The latest supported v3.2 CPU checkpoint downloads from the Hugging Face Hub on first use. Pass --smart_turn_model_path /path/to/model.onnx to use a local model, or --no_smart_turn to disable Smart Turn. Smart Turn is enabled by default for server sessions and the packaged local client.

Tune the completion cutoff with --smart_turn_threshold (default 0.5). A higher threshold makes ambiguous pauses more likely to use the longer speculative response grace.

STT, LLM, and TTS Parameters

model_name, torch_dtype, and device are exposed for each STT, LLM, and TTS implementation. STT and TTS parameters use the handler prefix, for example --stt_model_name or --qwen3_tts_device. LLM model selection and chat settings are shared across backends via unprefixed flags, for example --model_name and --chat_size; backend-specific flags use the responses_api_ prefix for the responses-api and chat-completions backends and the llm_ prefix for local backends.

For example:

bash
# Local transformers/mlx-lm backend
--model_name google/gemma-2b-it

# OpenAI-compatible backend
--llm_backend responses-api --model_name deepseek-chat --responses_api_base_url https://api.deepseek.com

Generation Parameters

Other generation parameters can be set using the handler prefix plus _gen_, for example --stt_gen_max_new_tokens 128 or --llm_gen_temperature 0.7. Parameters not yet exposed can be added to the relevant arguments class.

Big Bench Audio system tests

Run a pinned 40-question audio sample or all 1,000 Big Bench Audio questions through VAD, STT, the LLM, and TTS, with per-category answer accuracy, audio latency, and protocol failures in JSON reports. src/speech_to_speech/evals/big_bench_audio/Dockerfile.eval builds an image for local GPU runs or Hugging Face Jobs; scripts/prepare_eval_space.py optionally builds the image in a private HF Space. Start with four questions, then compare reports across revisions. See Big Bench Audio system tests.

Tool-use conversation tests

Run scripted tool-use conversations as text through a running server and count right calls, replies that promise a call without making it, speech before calls, and long-running results. A stand-in for the speech services makes it a quick check of any LLM backend. See Tool-use conversations.

Contributing

Issues and PRs are welcome. Good starting points are the open issues. For larger changes, open an issue first to discuss the approach.

For local development:

bash
uv sync --group dev
uv run pytest tests -q
uv run ruff check src tests
uv run ruff format --check src tests
uv run mypy src

To check turn ordering, Smart Turn timing, and Realtime routing on CPU:

bash
CUDA_VISIBLE_DEVICES='' uv run pytest -q \
  tests/test_speculative_turns.py \
  tests/test_smart_turn.py tests/test_stt_stale_filter.py \
  tests/test_audio_input_notifier.py tests/test_lm_output_processor.py \
  tests/openai_realtime/test_response_input_identity.py \
  tests/openai_realtime/test_realtime_service.py \
  tests/openai_realtime/test_speculative_turn_protocol.py

The response-input tests include a delayed tool completing during synthetic speech, using the packaged client coordinator, service, and VAD handler with mocked model output and VAD probabilities. Run that reproduction alone with:

bash
CUDA_VISIBLE_DEVICES='' uv run pytest tests/openai_realtime/test_response_input_identity.py -q -s

Star History

Star History Chart

Citations

If you use this pipeline, please also cite the component models you run. The defaults are:

Silero VAD

bibtex
@misc{SileroVAD,
  author = {Silero Team},
  title = {Silero VAD: pre-trained enterprise-grade Voice Activity Detector (VAD), Number Detector and Language Classifier},
  year = {2021},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/snakers4/silero-vad}},
  email = {hello@silero.ai}
}

Parakeet TDT

bibtex
@misc{parakeet-tdt,
  author = {NVIDIA},
  title = {Parakeet TDT 0.6B v3},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/nvidia/parakeet-tdt-0.6b-v3}}
}

Qwen3-TTS

bibtex
@misc{qwen3-tts,
  author = {Qwen Team},
  title = {Qwen3-TTS},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice}}
}

Citations for optional backends such as Kokoro, KittenTTS, Pocket TTS, ChatTTS, Whisper variants, Paraformer, and MMS live in the respective component READMEs.

#ai#assistant#language-model#machine-learning#python#speech#speech-synthesis#speech-to-text#speech-translation