feat(voice): 每用户 JARVIS——自定义名字/人设 + 自带豆包配置回落 + 语音不串主记忆
把 JARVIS 做成每用户独立:名字(你叫JARVIS别人叫星期五)、人设(与主偏好记忆分开)、 可自带豆包配置(齐全则用用户的,否则回落系统)。 - store/user_jarvis.go: sundynix_user_jarvis(user_id唯一;name/persona/火山creds,APIKey密文) + Get/Save(upsert) + AutoMigrate 注册 - voice_config.go resolveJarvis(uid): 火山配置用户优先系统兜底 + 取名字/人设 - voice_task.go: voiceSystemPrompt(name,persona)——简短是硬基线,名字/语气由用户定; buildVoiceGraph 带 name+persona;voice.go 会话升级时按用户解析 - dispatcher compose_compiler: 语音任务(useVoice)不拉主偏好记忆,改用用户 persona(保留短期历史) - jarvis.go + 路由: GET/PUT /api/v1/me/jarvis(用户级,api_key 脱敏/留空沿用) 真机验证:设 name=星期五+干净人设→语音答"我是星期五…"(自称新名、无糙话、4.4s), has_own_voice=false 用系统豆包。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -141,12 +141,22 @@ export class VoiceClient {
|
||||
// startListening 开一轮:连接(若需)→ 若正在朗读先打断 → 采麦克风 → 发 start。
|
||||
async startListening(graph?: string): Promise<void> {
|
||||
await this.connect();
|
||||
// 关键:在**用户手势**(点麦克风)里就把播放 AudioContext 建好并 resume——否则它在 WS 回调里
|
||||
// 惰性创建会处于 suspended 态,TTS 音频静默播不出(Chrome/WKWebView 的自动播放策略)。
|
||||
this.ensurePlayCtx();
|
||||
if (this.state === "speaking") this.bargeIn();
|
||||
this.send({ type: "start", graph });
|
||||
await this.startMic();
|
||||
this.setState("listening");
|
||||
}
|
||||
|
||||
// ensurePlayCtx 建/复用下行播放 AudioContext,并在 suspended 时 resume(自动播放策略要求手势内唤醒)。
|
||||
private ensurePlayCtx(): AudioContext {
|
||||
if (!this.playCtx) this.playCtx = new AudioContext();
|
||||
if (this.playCtx.state === "suspended") void this.playCtx.resume();
|
||||
return this.playCtx;
|
||||
}
|
||||
|
||||
// stopListening 结束本轮说话:停麦克风 + 发 end(服务端拿最终转写→提交任务)。
|
||||
stopListening(): void {
|
||||
this.stopMic();
|
||||
@@ -168,6 +178,7 @@ export class VoiceClient {
|
||||
this.micStream = stream;
|
||||
const ctx = new AudioContext();
|
||||
this.micCtx = ctx;
|
||||
if (ctx.state === "suspended") await ctx.resume(); // 防采集上下文挂起(无回调=不上行音频)
|
||||
const src = ctx.createMediaStreamSource(stream);
|
||||
const node = ctx.createScriptProcessor(4096, 1, 1);
|
||||
node.onaudioprocess = (ev) => {
|
||||
@@ -194,8 +205,8 @@ export class VoiceClient {
|
||||
|
||||
private enqueueAudio(buf: ArrayBuffer): void {
|
||||
if (buf.byteLength === 0) return;
|
||||
if (!this.playCtx) this.playCtx = new AudioContext();
|
||||
const ctx = this.playCtx;
|
||||
const ctx = this.ensurePlayCtx(); // 建/复用并 resume(防 WS 回调里上下文仍 suspended → 静默)
|
||||
|
||||
const i16 = new Int16Array(buf);
|
||||
const f32 = new Float32Array(i16.length);
|
||||
for (let i = 0; i < i16.length; i++) f32[i] = i16[i] / 0x8000;
|
||||
|
||||
Reference in New Issue
Block a user