Spaces:
Running
Running
Fall back to a voice the speech server has, so no coach goes silent
Browse filesFiles changed (4)
135 unmodified lines136137138139140141142135 unmodified lines| `SESSION_PROXY_URL` | Or piggyback another deployment's session API, e.g. `https://smolagents-hf-realtime-voice.hf.space/api` || `GRADER_BASE_URL`, `GRADER_MODEL` | Grade on the speech backend's own model through any OpenAI-compatible endpoint (e.g. the deployment's Gemma 4 31B); `GRADER_REASONING_EFFORT` (default `none`) and `GRADER_API_KEY` (default `HF_TOKEN`) go with it. The hosted chain below stays as fallback. || `GRADER_MODELS`, `WRITER_MODELS` | Comma-separated Inference Providers fallback chains (defaults: DeepSeek V4.1-Flash with reasoning off for grading, then DeepSeek V4-Pro and Gemma 4 31B; GLM-5.3 for writing; `model@effort` sets a model's reasoning effort) || `COACH_VOICE` | Overrides the TTS voice (by default Max uses `en-arthur_m`, Ada `en-maya_f`, Reachy Mini `Aiden`, Reachy 2 `auto-arthur_m` and Microduck `auto-clara_f`, voices of the hosted stack; a Qwen3-TTS CustomVoice backend needs e.g. `Aiden` / `Serena`) || `SERPER_API_KEY` | Adds Google results to research || `LOG_TURNS` | `1` logs each graded turn (the student's words and the grader's decision) for debugging || `GITHUB_TOKEN` | Optional, for reading GitHub repositories past the anonymous API limit (60 requests an hour per IP) |135 unmodified lines136137138139140141142135 unmodified lines| `SESSION_PROXY_URL` | Or piggyback another deployment's session API, e.g. `https://smolagents-hf-realtime-voice.hf.space/api` || `GRADER_BASE_URL`, `GRADER_MODEL` | Grade on the speech backend's own model through any OpenAI-compatible endpoint (e.g. the deployment's Gemma 4 31B); `GRADER_REASONING_EFFORT` (default `none`) and `GRADER_API_KEY` (default `HF_TOKEN`) go with it. The hosted chain below stays as fallback. || `GRADER_MODELS`, `WRITER_MODELS` | Comma-separated Inference Providers fallback chains (defaults: DeepSeek V4.1-Flash with reasoning off for grading, then DeepSeek V4-Pro and Gemma 4 31B; GLM-5.3 for writing; `model@effort` sets a model's reasoning effort) || `COACH_VOICE` | Overrides the TTS voice (by default Max uses `en-arthur_m`, Ada `en-maya_f`, Reachy Mini `Aiden`, Reachy 2 `auto-arthur_m` and Microduck `auto-clara_f`, voices of the hosted dev stack; when the speech server refuses a voice, the coach switches to its fallback, one of Qwen3-TTS's built-in speakers: Ryan, Serena, Eric, Vivian) || `SERPER_API_KEY` | Adds Google results to research || `LOG_TURNS` | `1` logs each graded turn (the student's words and the grader's decision) for debugging || `GITHUB_TOKEN` | Optional, for reading GitHub repositories past the anonymous API limit (60 requests an hour per IP) |
63 unmodified lines646566676869672 unmodified lines74274374474574674788 unmodified lines83683783883984084163 unmodified lines/** @type {RealtimeVoice | null} */ fillersFor: null,/** Grader tool calls not yet answered. */toolsPending: 0,/** The next question's own turn, asked once the verdict reply is written. @type {{ text: string, question: string, run: number, replyId: string } | null} */pendingAsk: null,/** The server lost the quiz (it restarted): going back to the lobby. */672 unmodified lines}return;}const ask = S.pendingAsk;if (ask && ask.replyId === id) {if (ask.run !== S.runId || S.phase !== "quiz" || asksQuestion(spoken || "", ask.question)) {88 unmodified lineselse if (S.snap.text) maybeSpeculate();$("#mic-ring").style.setProperty("--lvl", String(0.9 + Math.min(0.3, rms * 4)));});voice.addEventListener("error", (e) => {const d = /** @type {any} */ (e).detail;if (d.code === "closed") {63 unmodified lines6465666768697071672 unmodified lines74474574674774874975075175275375475575688 unmodified lines84584684784884985085185285385485585685785885986063 unmodified lines/** @type {RealtimeVoice | null} */ fillersFor: null,/** Grader tool calls not yet answered. */toolsPending: 0,/** Replies to redo once they end, because the speech server refused their voice. @type {Set<string>} */redoReplies: new Set(),/** The next question's own turn, asked once the verdict reply is written. @type {{ text: string, question: string, run: number, replyId: string } | null} */pendingAsk: null,/** The server lost the quiz (it restarted): going back to the lobby. */672 unmodified lines}return;}if (S.redoReplies.delete(id)) {// Its audio was refused: ask for it again, in the fallback voice (a// question turn waiting on it waits on the new one instead).if (S.pendingAsk?.replyId === id) S.pendingAsk.replyId = "";voice.redo(id);return;}const ask = S.pendingAsk;if (ask && ask.replyId === id) {if (ask.run !== S.runId || S.phase !== "quiz" || asksQuestion(spoken || "", ask.question)) {88 unmodified lineselse if (S.snap.text) maybeSpeculate();$("#mic-ring").style.setProperty("--lvl", String(0.9 + Math.min(0.3, rms * 4)));});voice.addEventListener("voice-rejected", (e) => {// The speech server doesn't have this coach's voice: switch to its// fallback and say the line again once the silent reply ends.const d = /** @type {any} */ (e).detail;const fallback = /** @type {any} */ (S.coach).fallbackVoice;if (!fallback || d.voice === fallback || S.cfg.voice) return;console.warn(`[voice] ${d.voice} is not available here; switching to ${fallback}`);voice.setVoice(fallback);S.redoReplies.add(d.responseId);});voice.addEventListener("error", (e) => {const d = /** @type {any} */ (e).detail;if (d.code === "closed") {
17 unmodified lines18192021222311 unmodified lines35363738394013 unmodified lines5455565758594 unmodified lines64656667686917 unmodified linesmax: {name: "Max",voice: "en-arthur_m",renderer: "talkinghead",lipGain: 1.35,jawGain: 1,11 unmodified linesada: {name: "Ada",voice: "en-maya_f",renderer: "splat",lipGain: 1,jawGain: 0.6,13 unmodified linesreachy2: {name: "Reachy 2",voice: "auto-arthur_m",renderer: "robot",robot: "reachy2",lipGain: 1,4 unmodified linesduck: {name: "Microduck",voice: "auto-clara_f",renderer: "robot",robot: "duck",lipGain: 1,17 unmodified lines18192021222324252611 unmodified lines3839404142434413 unmodified lines585960616263644 unmodified lines6970717273747517 unmodified linesmax: {name: "Max",voice: "en-arthur_m",// Used when the speech server doesn't have the voice above (production// only has Qwen3-TTS's built-in speakers).fallbackVoice: "Ryan",renderer: "talkinghead",lipGain: 1.35,jawGain: 1,11 unmodified linesada: {name: "Ada",voice: "en-maya_f",fallbackVoice: "Serena",renderer: "splat",lipGain: 1,jawGain: 0.6,13 unmodified linesreachy2: {name: "Reachy 2",voice: "auto-arthur_m",fallbackVoice: "Eric",renderer: "robot",robot: "reachy2",lipGain: 1,4 unmodified linesduck: {name: "Microduck",voice: "auto-clara_f",fallbackVoice: "Vivian",renderer: "robot",robot: "duck",lipGain: 1,
76 unmodified lines777879808182251 unmodified lines33433533633733833957 unmodified lines39739839940040140240340488 unmodified lines49349449549649749876 unmodified linesthis.lastSpeechStart = 0;/** What the response.create in flight was for, to retry it right if the server refuses it. @type {{ instructions?: string, extra?: any, capture?: string } | null} */this.pendingCreate = null;this.speaking = false;/** Assistant message item of each response (for truncation). @type {Map<string, string>} */this.items = new Map();251 unmodified linesif (out) this.deleteItemId(out);}/** Remove a reply from the conversation history. @param {string} responseId */deleteItem(responseId) {const itemId = this.items.get(responseId);57 unmodified linesbreak;case "response.created": {this.awaitingCreate = false;this.pendingCreate = null;this.activeResponse = ev.response?.id || "resp";const key = ev.response?.metadata?.viva_capture;if (key) {this.captures.set(this.activeResponse, { key, chunks: [], text: "" });88 unmodified linesbreak;}this.awaitingCreate = false;this.emit("error", { message: err.message || "Voice server error", code });break;}76 unmodified lines7778798081828384251 unmodified lines33633733833934034134234334434534634734834935035135235335435535635735835957 unmodified lines41741841942042142242342442542642788 unmodified lines51651751851952052152252352452552676 unmodified linesthis.lastSpeechStart = 0;/** What the response.create in flight was for, to retry it right if the server refuses it. @type {{ instructions?: string, extra?: any, capture?: string } | null} */this.pendingCreate = null;/** How each reply was asked for, to redo one. @type {Map<string, { instructions?: string, extra?: any, capture?: string } | null>} */this.madeWith = new Map();this.speaking = false;/** Assistant message item of each response (for truncation). @type {Map<string, string>} */this.items = new Map();251 unmodified linesif (out) this.deleteItemId(out);}/** Switch the voice for the next replies. @param {string} voice */setVoice(voice) {this.voice = voice;this.send({ type: "session.update", session: { type: "realtime", audio: { output: { format: { type: "audio/pcm", rate: RATE }, voice } } } });}/*** Ask again for a reply that failed: drop it from the history, then request* it the same way (a plain reply when the model started it on its own).* @param {string} responseId*/redo(responseId) {const made = this.madeWith.get(responseId);if (made?.capture) return;this.deleteItem(responseId);this.respond(made?.instructions, made?.extra);}/** Remove a reply from the conversation history. @param {string} responseId */deleteItem(responseId) {const itemId = this.items.get(responseId);57 unmodified linesbreak;case "response.created": {this.awaitingCreate = false;const made = this.pendingCreate;this.pendingCreate = null;this.activeResponse = ev.response?.id || "resp";if (this.madeWith.size > 50) this.madeWith.clear();this.madeWith.set(this.activeResponse, made);const key = ev.response?.metadata?.viva_capture;if (key) {this.captures.set(this.activeResponse, { key, chunks: [], text: "" });88 unmodified linesbreak;}this.awaitingCreate = false;if (/speech server returned HTTP 4\d\d/.test(err.message || "") && this.activeResponse) {// The speech server refused this voice (it doesn't know it): the// reply's words came, its audio won't.this.emit("voice-rejected", { responseId: this.activeResponse, voice: this.voice });}this.emit("error", { message: err.message || "Voice server error", code });break;}
README.md+1-1
static/js/app.js+19
static/js/coaches.js+6
static/js/realtime.js+28