mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-02 17:32:50 +08:00
Route voice playback through a hidden <audio> element for device switching
AudioContext.setSinkId only exists in Chrome; HTMLMediaElement.setSinkId is supported more broadly (including Firefox 130+). Playback now goes through a MediaStreamAudioDestinationNode into a hidden <audio> element so output device switching actually takes effect outside Chrome/Edge.
This commit is contained in:
1 parent
b3e55a60b5
commit
a5c1ae62ff
2 files changed
+48
-16
No files matched your search
+3
-3
@@ -7,7 +7,6 @@ import {
|
||||
hasNativeOutputPicker,
|
||||
listAudioOutputDevices,
|
||||
pickAudioOutputDevice,
|
||||
setAudioOutputDevice,
|
||||
} from "./voice";
|
||||
|
||||
const GATEWAY_URL = "ws://localhost:8080";
|
||||
@@ -293,9 +292,10 @@ function App() {
|
||||
socket.onclose = () => {
|
||||
setConnected(false);
|
||||
stopMic();
|
||||
audioPlayerRef.current?.dispose();
|
||||
audioPlayerRef.current = null;
|
||||
audioContextRef.current?.close();
|
||||
audioContextRef.current = null;
|
||||
audioPlayerRef.current = null;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -327,7 +327,7 @@ function App() {
|
||||
const handleOutputDeviceChange = async (deviceId: string, label?: string) => {
|
||||
setOutputDeviceId(deviceId);
|
||||
setOutputDeviceLabel(label || (deviceId ? `Output ${deviceId.slice(0, 6)}` : "System default"));
|
||||
if (audioContextRef.current) await setAudioOutputDevice(audioContextRef.current, deviceId);
|
||||
await audioPlayerRef.current?.setOutputDevice(deviceId);
|
||||
};
|
||||
|
||||
const handlePickOutputDevice = async () => {
|
||||
|
||||
Reference in new issue
Block a user