mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
Add local session recording (Aufnahme)
Wires up the Extras menu's Aufnahme starten/beenden items: mixes the incoming voice playback and outgoing mic signal into a MediaRecorder and downloads the result as webm on stop. Multitrack recording stays disabled (needs a plugin-equivalent per-client split not modeled here). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7bcced06fd
commit
67c4bc1072
3 files changed
+110
-11
No files matched your search
@@ -541,6 +541,20 @@
|
|||||||
background: color-mix(in srgb, var(--log-error) 30%, var(--button-bg-1)) !important;
|
background: color-mix(in srgb, var(--log-error) 30%, var(--button-bg-1)) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ts-recording-on {
|
||||||
|
background: color-mix(in srgb, var(--log-error) 35%, var(--button-bg-1)) !important;
|
||||||
|
animation: ts-recording-pulse 1.4s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes ts-recording-pulse {
|
||||||
|
0%, 100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.55;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.ts-client-away-message {
|
.ts-client-away-message {
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
|
|||||||
+91
-11
@@ -2049,6 +2049,7 @@ function AppInner() {
|
|||||||
const nicknameBackdrop = useBackdropDismiss(() => setChangeNicknameOpen(false));
|
const nicknameBackdrop = useBackdropDismiss(() => setChangeNicknameOpen(false));
|
||||||
const [contacts, setContacts] = useState<Contact[]>(() => loadContacts());
|
const [contacts, setContacts] = useState<Contact[]>(() => loadContacts());
|
||||||
const [contactsOpen, setContactsOpen] = useState(false);
|
const [contactsOpen, setContactsOpen] = useState(false);
|
||||||
|
const [recording, setRecording] = useState(false);
|
||||||
const whisperLogIdRef = useRef(0);
|
const whisperLogIdRef = useRef(0);
|
||||||
const prevWhisperTargetsRef = useRef<{ channels: Set<number>; clients: Set<number> } | null>(null);
|
const prevWhisperTargetsRef = useRef<{ channels: Set<number>; clients: Set<number> } | null>(null);
|
||||||
|
|
||||||
@@ -2067,6 +2068,9 @@ function AppInner() {
|
|||||||
const audioContextRef = useRef<AudioContext | null>(null);
|
const audioContextRef = useRef<AudioContext | null>(null);
|
||||||
const audioPlayerRef = useRef<AudioPlayer | null>(null);
|
const audioPlayerRef = useRef<AudioPlayer | null>(null);
|
||||||
const micCaptureRef = useRef<MicCapture | null>(null);
|
const micCaptureRef = useRef<MicCapture | null>(null);
|
||||||
|
const recorderRef = useRef<MediaRecorder | null>(null);
|
||||||
|
const recordDestRef = useRef<MediaStreamAudioDestinationNode | null>(null);
|
||||||
|
const recordedChunksRef = useRef<Blob[]>([]);
|
||||||
const activeTabRef = useRef<ActiveTab>("channel");
|
const activeTabRef = useRef<ActiveTab>("channel");
|
||||||
const hasConnectedRef = useRef(false);
|
const hasConnectedRef = useRef(false);
|
||||||
// Set when a "disconnected" event is received, so the socket's onclose
|
// Set when a "disconnected" event is received, so the socket's onclose
|
||||||
@@ -2266,6 +2270,7 @@ function AppInner() {
|
|||||||
previousSocket.close();
|
previousSocket.close();
|
||||||
}
|
}
|
||||||
stopMic();
|
stopMic();
|
||||||
|
stopRecording();
|
||||||
audioPlayerRef.current?.dispose();
|
audioPlayerRef.current?.dispose();
|
||||||
audioPlayerRef.current = null;
|
audioPlayerRef.current = null;
|
||||||
audioContextRef.current?.close();
|
audioContextRef.current?.close();
|
||||||
@@ -2450,6 +2455,7 @@ function AppInner() {
|
|||||||
setWhisperLog([]);
|
setWhisperLog([]);
|
||||||
prevWhisperTargetsRef.current = null;
|
prevWhisperTargetsRef.current = null;
|
||||||
stopMic();
|
stopMic();
|
||||||
|
stopRecording();
|
||||||
appendLog({ text: `Disconnected: ${data.reason}`, kind: "info" });
|
appendLog({ text: `Disconnected: ${data.reason}`, kind: "info" });
|
||||||
logClient("info", "Connection", `Disconnected: ${data.reason}`);
|
logClient("info", "Connection", `Disconnected: ${data.reason}`);
|
||||||
if (wasConnected) void playSound("disconnect");
|
if (wasConnected) void playSound("disconnect");
|
||||||
@@ -2484,6 +2490,7 @@ function AppInner() {
|
|||||||
cleanDisconnectRef.current = false;
|
cleanDisconnectRef.current = false;
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
stopMic();
|
stopMic();
|
||||||
|
stopRecording();
|
||||||
audioPlayerRef.current?.dispose();
|
audioPlayerRef.current?.dispose();
|
||||||
audioPlayerRef.current = null;
|
audioPlayerRef.current = null;
|
||||||
audioContextRef.current?.close();
|
audioContextRef.current?.close();
|
||||||
@@ -2761,6 +2768,7 @@ function AppInner() {
|
|||||||
setMicOn(true);
|
setMicOn(true);
|
||||||
refreshOutputDevices();
|
refreshOutputDevices();
|
||||||
refreshInputDevices();
|
refreshInputDevices();
|
||||||
|
connectMicToRecorder();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
appendLog({ text: `Microphone error: ${(error as Error).message}`, kind: "error" });
|
appendLog({ text: `Microphone error: ${(error as Error).message}`, kind: "error" });
|
||||||
}
|
}
|
||||||
@@ -2822,6 +2830,56 @@ function AppInner() {
|
|||||||
socketRef.current?.send(JSON.stringify({ type: "setOutputMuted", muted: !outputMutedRef.current }));
|
socketRef.current?.send(JSON.stringify({ type: "setOutputMuted", muted: !outputMutedRef.current }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Connects the current mic (if any) into the active recording, so a device
|
||||||
|
// switch or a mic (re)start mid-recording doesn't silently drop it from the mix.
|
||||||
|
const connectMicToRecorder = () => {
|
||||||
|
const dest = recordDestRef.current;
|
||||||
|
const source = micCaptureRef.current?.getSourceNode();
|
||||||
|
if (dest && source) source.connect(dest);
|
||||||
|
};
|
||||||
|
|
||||||
|
const startRecording = () => {
|
||||||
|
if (recorderRef.current) return;
|
||||||
|
const audioContext = ensureAudioContext();
|
||||||
|
const dest = audioContext.createMediaStreamDestination();
|
||||||
|
recordDestRef.current = dest;
|
||||||
|
audioPlayerRef.current?.getInputNode().connect(dest);
|
||||||
|
connectMicToRecorder();
|
||||||
|
|
||||||
|
recordedChunksRef.current = [];
|
||||||
|
const recorder = new MediaRecorder(dest.stream);
|
||||||
|
recorder.ondataavailable = (event) => {
|
||||||
|
if (event.data.size > 0) recordedChunksRef.current.push(event.data);
|
||||||
|
};
|
||||||
|
recorder.onstop = () => {
|
||||||
|
const blob = new Blob(recordedChunksRef.current, { type: recorder.mimeType || "audio/webm" });
|
||||||
|
recordedChunksRef.current = [];
|
||||||
|
const extension = blob.type.includes("ogg") ? "ogg" : "webm";
|
||||||
|
const safeServerName = (serverName || "session").replace(/[\\/:*?"<>|]+/g, "_").trim() || "session";
|
||||||
|
const filename = `webspeak3-${safeServerName}-${new Date().toISOString().replace(/[:.]/g, "-")}.${extension}`;
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
logClient("info", "Recording", `Saved recording as ${filename}`);
|
||||||
|
};
|
||||||
|
recorder.start();
|
||||||
|
recorderRef.current = recorder;
|
||||||
|
setRecording(true);
|
||||||
|
logClient("info", "Recording", "Started local recording");
|
||||||
|
};
|
||||||
|
|
||||||
|
const stopRecording = () => {
|
||||||
|
recorderRef.current?.stop();
|
||||||
|
recorderRef.current = null;
|
||||||
|
recordDestRef.current = null;
|
||||||
|
setRecording(false);
|
||||||
|
};
|
||||||
|
|
||||||
const handleSetNickname = (newNickname: string) => {
|
const handleSetNickname = (newNickname: string) => {
|
||||||
socketRef.current?.send(JSON.stringify({ type: "setNickname", nickname: newNickname }));
|
socketRef.current?.send(JSON.stringify({ type: "setNickname", nickname: newNickname }));
|
||||||
};
|
};
|
||||||
@@ -3230,17 +3288,34 @@ function AppInner() {
|
|||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
<div className="ts-menu-separator" />
|
<div className="ts-menu-separator" />
|
||||||
{[
|
<button
|
||||||
{ icon: "🔴", label: t("menu.extras.startRecording"), shortcut: "Strg+Umschalt+R" },
|
className="ts-menu-item"
|
||||||
{ icon: "🔴", label: t("menu.extras.startMultitrackRecording") },
|
disabled={recording}
|
||||||
{ icon: "⏹️", label: t("menu.extras.stopRecording"), shortcut: "Strg+Umschalt+T" },
|
onClick={() => {
|
||||||
].map((item) => (
|
startRecording();
|
||||||
<button key={item.label} className="ts-menu-item" disabled>
|
setExtrasMenuOpen(false);
|
||||||
<span className="ts-menu-item-icon">{item.icon}</span>
|
}}
|
||||||
<span className="ts-menu-item-label">{item.label}</span>
|
>
|
||||||
{item.shortcut && <span className="ts-menu-item-shortcut">{item.shortcut}</span>}
|
<span className="ts-menu-item-icon">🔴</span>
|
||||||
</button>
|
<span className="ts-menu-item-label">{t("menu.extras.startRecording")}</span>
|
||||||
))}
|
<span className="ts-menu-item-shortcut">Strg+Umschalt+R</span>
|
||||||
|
</button>
|
||||||
|
<button className="ts-menu-item" disabled>
|
||||||
|
<span className="ts-menu-item-icon">🔴</span>
|
||||||
|
<span className="ts-menu-item-label">{t("menu.extras.startMultitrackRecording")}</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="ts-menu-item"
|
||||||
|
disabled={!recording}
|
||||||
|
onClick={() => {
|
||||||
|
stopRecording();
|
||||||
|
setExtrasMenuOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="ts-menu-item-icon">⏹️</span>
|
||||||
|
<span className="ts-menu-item-label">{t("menu.extras.stopRecording")}</span>
|
||||||
|
<span className="ts-menu-item-shortcut">Strg+Umschalt+T</span>
|
||||||
|
</button>
|
||||||
<div className="ts-menu-separator" />
|
<div className="ts-menu-separator" />
|
||||||
<button
|
<button
|
||||||
className="ts-menu-item"
|
className="ts-menu-item"
|
||||||
@@ -3423,6 +3498,11 @@ function AppInner() {
|
|||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
|
{recording && (
|
||||||
|
<button className="ts-icon-button ts-recording-on" onClick={stopRecording} title={t("menu.extras.stopRecording")}>
|
||||||
|
🔴
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<span className="ts-toolbar-sep" />
|
<span className="ts-toolbar-sep" />
|
||||||
<button
|
<button
|
||||||
className="ts-icon-button"
|
className="ts-icon-button"
|
||||||
|
|||||||
@@ -134,6 +134,11 @@ export class MicCapture {
|
|||||||
this.silence.connect(this.context.destination);
|
this.silence.connect(this.context.destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The raw mic input node, e.g. to additionally route it into a recorder. */
|
||||||
|
getSourceNode(): AudioNode | null {
|
||||||
|
return this.source;
|
||||||
|
}
|
||||||
|
|
||||||
/** Routes the raw mic signal to `destination` too, so you can hear yourself (a mic test), until disabled again. */
|
/** Routes the raw mic signal to `destination` too, so you can hear yourself (a mic test), until disabled again. */
|
||||||
setMonitoring(enabled: boolean, destination: AudioNode): void {
|
setMonitoring(enabled: boolean, destination: AudioNode): void {
|
||||||
if (!this.source) return;
|
if (!this.source) return;
|
||||||
|
|||||||
Reference in new issue
Block a user