feat(qwen-audio): add Alibaba Cloud Qwen-Audio Realtime service integration

- Introduced Qwen-Audio Realtime service for speech-to-speech processing in Pipecat.
- Updated interface catalog to include Qwen-Audio Realtime capabilities.
- Enhanced model resource testing to support new service.
- Added configuration options for audio sample rates and turn detection modes.
- Updated documentation to reflect integration details and usage instructions.
This commit is contained in:
Xin Wang
2026-07-21 15:57:43 +08:00
parent f027ed99b7
commit 774825593d
10 changed files with 866 additions and 19 deletions

View File

@@ -178,8 +178,24 @@ def create_tts(cfg: AssistantConfig):
)
def realtime_audio_sample_rates(cfg: AssistantConfig) -> tuple[int, int]:
"""Resolve provider defaults once for both the service and pipeline.
Values remain overridable for future model versions with different audio
formats, while today's Qwen-Audio contract defaults to 16 kHz in/24 kHz out.
"""
default_input_rate = (
16_000 if cfg.realtime_interface_type == "qwen-audio-realtime" else 24_000
)
return (
int(cfg.realtime_values.get("inputSampleRate") or default_input_rate),
int(cfg.realtime_values.get("outputSampleRate") or 24_000),
)
def create_realtime_service(cfg: AssistantConfig, *, instructions: str):
"""Create a speech-to-speech service that owns STT, LLM, and TTS."""
input_sample_rate, output_sample_rate = realtime_audio_sample_rates(cfg)
if cfg.realtime_interface_type == "stepfun-realtime":
from services.pipecat.stepfun_realtime import StepFunRealtimeService
@@ -189,12 +205,8 @@ def create_realtime_service(cfg: AssistantConfig, *, instructions: str):
base_url=_require(cfg.realtime_base_url, "Realtime apiUrl"),
instructions=instructions,
voice=str(cfg.realtime_values.get("voice") or "linjiajiejie"),
input_sample_rate=int(
cfg.realtime_values.get("inputSampleRate") or 24000
),
output_sample_rate=int(
cfg.realtime_values.get("outputSampleRate") or 24000
),
input_sample_rate=input_sample_rate,
output_sample_rate=output_sample_rate,
prefix_padding_ms=int(
cfg.realtime_values.get("prefixPaddingMs") or 500
),
@@ -205,4 +217,26 @@ def create_realtime_service(cfg: AssistantConfig, *, instructions: str):
cfg.realtime_values.get("energyAwakenessThreshold") or 2500
),
)
if cfg.realtime_interface_type == "qwen-audio-realtime":
from services.pipecat.qwen_audio_realtime import QwenAudioRealtimeService
return QwenAudioRealtimeService(
api_key=_require(cfg.realtime_api_key, "Realtime apiKey"),
model=_require(cfg.realtimeModel, "Realtime modelId"),
base_url=_require(cfg.realtime_base_url, "Realtime apiUrl"),
instructions=instructions,
voice=str(cfg.realtime_values.get("voice") or "longanqian"),
input_sample_rate=input_sample_rate,
output_sample_rate=output_sample_rate,
turn_detection_mode=str(
cfg.realtime_values.get("turnDetection") or "server_vad"
),
vad_threshold=float(cfg.realtime_values.get("vadThreshold", 0.5)),
silence_duration_ms=int(
cfg.realtime_values.get("silenceDurationMs") or 800
),
max_history_turns=int(
cfg.realtime_values.get("maxHistoryTurns") or 20
),
)
raise ValueError(f"不支持的 Realtime 接口类型: {cfg.realtime_interface_type}")