Skip to content

Voice Forwarding

DNTOF edited this page Sep 24, 2026 · 4 revisions

语音转发(SPY)

voice_enabled: true 时在 voice_port(默认 8082)提供实时语音。全频道 Opus 解码为 48kHz 单声道 float32 PCM。

对齐 2.6.0 PEAK。

鉴权

版本 方式
2.6.0 PEAK(现行) 握手头 Authorization: Bearer / X-SLDataAPI-Key(不要把 Key 放进 URL)
2.5.x(历史) GET /ws?key=<control_token> 或 X-Control-Token

端点

路径 说明
GET /ws 升级 WebSocket,语音流
GET /status JSON:当前说话玩家(1.5s 无包视为静音)

帧格式

  1. 文本 {"type":"hello","sampleRate":48000,"channels":1,"format":"float32"}
  2. 文本 speaker:昵称、userid、playerid、role、channel(频道/角色变化时)
  3. 二进制语音:[0]=0x01 [1]=channel [2-3]=playerId LE [4-7]=seq LE [8..]=float32 PCM(约 10ms/帧)

实现要点

  • 事件:SendingVoiceMessage / VoiceTransceiver.ServerReceiveMessage
  • 解码器按 netId 维护;异常重建;不用 ReferenceHub 作长期键
  • 发送:Poll 可写检查,满则丢帧;持续不可写断连;主线程不阻塞
  • 连接上限 8;握手超时 10s

可选:定稿 zip 自动上传到 WebDAV(仅 https://),见 Configuration。

录音存档见 Voice-Recording(需 voice_record_enabled)。

Clone this wiki locally