mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 09:52:50 +08:00
Compare commits
4
Commits
d64b25f22f
...
ced63fdb2a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ced63fdb2a | ||
|
|
d860aa61e5 | ||
|
|
341a1644a6 | ||
|
|
97421ff2de |
No files matched your search
+122
-16
@@ -398,9 +398,14 @@ const PLAYBACK_VOLUME_KEY = "webspeak3:playback-volume";
|
|||||||
const NOISE_SUPPRESSION_KEY = "webspeak3:noise-suppression";
|
const NOISE_SUPPRESSION_KEY = "webspeak3:noise-suppression";
|
||||||
const ECHO_CANCELLATION_KEY = "webspeak3:echo-cancellation";
|
const ECHO_CANCELLATION_KEY = "webspeak3:echo-cancellation";
|
||||||
const AUTO_GAIN_CONTROL_KEY = "webspeak3:auto-gain-control";
|
const AUTO_GAIN_CONTROL_KEY = "webspeak3:auto-gain-control";
|
||||||
|
const AUTO_VOLUME_KEY = "webspeak3:auto-volume";
|
||||||
|
const OWN_MIC_CLICKS_KEY = "webspeak3:own-mic-clicks";
|
||||||
|
const OTHER_MIC_CLICKS_KEY = "webspeak3:other-mic-clicks";
|
||||||
const AEC3_ENABLED_KEY = "webspeak3:aec3-enabled";
|
const AEC3_ENABLED_KEY = "webspeak3:aec3-enabled";
|
||||||
const VAD_HANGOVER_KEY = "webspeak3:vad-hangover";
|
const VAD_HANGOVER_KEY = "webspeak3:vad-hangover";
|
||||||
const PUSH_TO_TALK_KEY = "webspeak3:push-to-talk";
|
const PUSH_TO_TALK_KEY = "webspeak3:push-to-talk";
|
||||||
|
const CONTINUOUS_KEY = "webspeak3:continuous-transmission";
|
||||||
|
const TYPING_ATTENUATION_KEY = "webspeak3:typing-attenuation";
|
||||||
const PTT_BINDING_KEY = "webspeak3:ptt-key";
|
const PTT_BINDING_KEY = "webspeak3:ptt-key";
|
||||||
const DESIGN_THEME_KEY = "webspeak3:design-theme";
|
const DESIGN_THEME_KEY = "webspeak3:design-theme";
|
||||||
// The user's actual pick - "standard" | "nova" | "greenteaspeak" | "custom:<id>".
|
// The user's actual pick - "standard" | "nova" | "greenteaspeak" | "custom:<id>".
|
||||||
@@ -5525,6 +5530,12 @@ interface AudioSettings {
|
|||||||
onRefreshOutputDevices: () => void;
|
onRefreshOutputDevices: () => void;
|
||||||
playbackVolume: number;
|
playbackVolume: number;
|
||||||
onPlaybackVolumeChange: (v: number) => void;
|
onPlaybackVolumeChange: (v: number) => void;
|
||||||
|
autoVolume: boolean;
|
||||||
|
onAutoVolumeChange: (v: boolean) => void;
|
||||||
|
ownMicClicks: boolean;
|
||||||
|
onOwnMicClicksChange: (v: boolean) => void;
|
||||||
|
otherMicClicks: boolean;
|
||||||
|
onOtherMicClicksChange: (v: boolean) => void;
|
||||||
onPlayTestTone: () => void;
|
onPlayTestTone: () => void;
|
||||||
inputDevices: MediaDeviceInfo[];
|
inputDevices: MediaDeviceInfo[];
|
||||||
inputDeviceId: string;
|
inputDeviceId: string;
|
||||||
@@ -5540,6 +5551,10 @@ interface AudioSettings {
|
|||||||
onVadHangoverChange: (v: number) => void;
|
onVadHangoverChange: (v: number) => void;
|
||||||
pushToTalk: boolean;
|
pushToTalk: boolean;
|
||||||
onPushToTalkChange: (on: boolean) => void;
|
onPushToTalkChange: (on: boolean) => void;
|
||||||
|
continuous: boolean;
|
||||||
|
onContinuousChange: (on: boolean) => void;
|
||||||
|
typingAttenuation: boolean;
|
||||||
|
onTypingAttenuationChange: (on: boolean) => void;
|
||||||
pttBinding: PttBinding | null;
|
pttBinding: PttBinding | null;
|
||||||
onPttBindingChange: (binding: PttBinding) => void;
|
onPttBindingChange: (binding: PttBinding) => void;
|
||||||
noiseSuppressionEnabled: boolean;
|
noiseSuppressionEnabled: boolean;
|
||||||
@@ -5711,15 +5726,15 @@ function WiedergabePanel({ audio }: { audio: AudioSettings }) {
|
|||||||
<fieldset className="ts-options-fieldset">
|
<fieldset className="ts-options-fieldset">
|
||||||
<legend>{t("playback.options")}</legend>
|
<legend>{t("playback.options")}</legend>
|
||||||
<label className="ts-options-checkbox">
|
<label className="ts-options-checkbox">
|
||||||
<input type="checkbox" checked disabled readOnly />
|
<input type="checkbox" checked={audio.autoVolume} onChange={(e) => audio.onAutoVolumeChange(e.target.checked)} />
|
||||||
{t("playback.autoVolume")}
|
{t("playback.autoVolume")}
|
||||||
</label>
|
</label>
|
||||||
<label className="ts-options-checkbox">
|
<label className="ts-options-checkbox">
|
||||||
<input type="checkbox" checked disabled readOnly />
|
<input type="checkbox" checked={audio.ownMicClicks} onChange={(e) => audio.onOwnMicClicksChange(e.target.checked)} />
|
||||||
{t("playback.ownMicClicks")}
|
{t("playback.ownMicClicks")}
|
||||||
</label>
|
</label>
|
||||||
<label className="ts-options-checkbox">
|
<label className="ts-options-checkbox">
|
||||||
<input type="checkbox" disabled readOnly />
|
<input type="checkbox" checked={audio.otherMicClicks} onChange={(e) => audio.onOtherMicClicksChange(e.target.checked)} />
|
||||||
{t("playback.otherMicClicks")}
|
{t("playback.otherMicClicks")}
|
||||||
</label>
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@@ -5776,15 +5791,26 @@ function AufnahmePanel({ audio }: { audio: AudioSettings }) {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<label className="ts-options-radio">
|
<label className="ts-options-radio">
|
||||||
<input type="radio" name="activation" disabled readOnly />
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="activation"
|
||||||
|
checked={!audio.pushToTalk && audio.continuous}
|
||||||
|
onChange={() => {
|
||||||
|
audio.onPushToTalkChange(false);
|
||||||
|
audio.onContinuousChange(true);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
{t("recording.continuous")}
|
{t("recording.continuous")}
|
||||||
</label>
|
</label>
|
||||||
<label className="ts-options-radio">
|
<label className="ts-options-radio">
|
||||||
<input
|
<input
|
||||||
type="radio"
|
type="radio"
|
||||||
name="activation"
|
name="activation"
|
||||||
checked={!audio.pushToTalk}
|
checked={!audio.pushToTalk && !audio.continuous}
|
||||||
onChange={() => audio.onPushToTalkChange(false)}
|
onChange={() => {
|
||||||
|
audio.onPushToTalkChange(false);
|
||||||
|
audio.onContinuousChange(false);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{t("recording.voiceActivation")}
|
{t("recording.voiceActivation")}
|
||||||
</label>
|
</label>
|
||||||
@@ -5823,7 +5849,11 @@ function AufnahmePanel({ audio }: { audio: AudioSettings }) {
|
|||||||
<legend>{t("recording.dsp")}</legend>
|
<legend>{t("recording.dsp")}</legend>
|
||||||
<div className="ts-options-dsp-grid">
|
<div className="ts-options-dsp-grid">
|
||||||
<label className="ts-options-checkbox">
|
<label className="ts-options-checkbox">
|
||||||
<input type="checkbox" disabled readOnly />
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={audio.typingAttenuation}
|
||||||
|
onChange={(e) => audio.onTypingAttenuationChange(e.target.checked)}
|
||||||
|
/>
|
||||||
{t("recording.typingAttenuation")}
|
{t("recording.typingAttenuation")}
|
||||||
</label>
|
</label>
|
||||||
<label className="ts-options-checkbox">
|
<label className="ts-options-checkbox">
|
||||||
@@ -7277,6 +7307,11 @@ function AppInner() {
|
|||||||
const [vadThreshold, setVadThreshold] = useState(0.02);
|
const [vadThreshold, setVadThreshold] = useState(0.02);
|
||||||
const [vadHangover, setVadHangover] = useState(() => loadNumberPref(VAD_HANGOVER_KEY, 0.3));
|
const [vadHangover, setVadHangover] = useState(() => loadNumberPref(VAD_HANGOVER_KEY, 0.3));
|
||||||
const [pushToTalk, setPushToTalk] = useState(() => loadBoolPref(PUSH_TO_TALK_KEY, false));
|
const [pushToTalk, setPushToTalk] = useState(() => loadBoolPref(PUSH_TO_TALK_KEY, false));
|
||||||
|
// Only matters while pushToTalk is off: send all the time instead of voice activation.
|
||||||
|
const [continuous, setContinuous] = useState(() => loadBoolPref(CONTINUOUS_KEY, false));
|
||||||
|
const continuousRef = useRef(continuous);
|
||||||
|
const [typingAttenuation, setTypingAttenuation] = useState(() => loadBoolPref(TYPING_ATTENUATION_KEY, false));
|
||||||
|
const typingAttenuationRef = useRef(typingAttenuation);
|
||||||
const [pttBinding, setPttBinding] = useState<PttBinding | null>(loadPttBinding);
|
const [pttBinding, setPttBinding] = useState<PttBinding | null>(loadPttBinding);
|
||||||
const [pttPressed, setPttPressed] = useState(false);
|
const [pttPressed, setPttPressed] = useState(false);
|
||||||
// Read when a new MicCapture is created, which happens outside render.
|
// Read when a new MicCapture is created, which happens outside render.
|
||||||
@@ -7299,6 +7334,13 @@ function AppInner() {
|
|||||||
// Off by default: a heavier, opt-in alternative/supplement to native AEC for
|
// Off by default: a heavier, opt-in alternative/supplement to native AEC for
|
||||||
// speaker+mic (no headset) setups (github.com/WebSpeak3/webspeak3 issue #2).
|
// speaker+mic (no headset) setups (github.com/WebSpeak3/webspeak3 issue #2).
|
||||||
const [aec3Enabled, setAec3Enabled] = useState(() => loadBoolPref(AEC3_ENABLED_KEY, false));
|
const [aec3Enabled, setAec3Enabled] = useState(() => loadBoolPref(AEC3_ENABLED_KEY, false));
|
||||||
|
// Playback options. The clicks themselves are sounds (micClickOn/Off).
|
||||||
|
const [autoVolume, setAutoVolume] = useState(() => loadBoolPref(AUTO_VOLUME_KEY, true));
|
||||||
|
const [ownMicClicks, setOwnMicClicks] = useState(() => loadBoolPref(OWN_MIC_CLICKS_KEY, false));
|
||||||
|
const [otherMicClicks, setOtherMicClicks] = useState(() => loadBoolPref(OTHER_MIC_CLICKS_KEY, false));
|
||||||
|
// Read from the socket handler, which only sees the first render's state.
|
||||||
|
const otherMicClicksRef = useRef(otherMicClicks);
|
||||||
|
const talkersRef = useRef<Set<number>>(new Set());
|
||||||
const [aec3Loading, setAec3Loading] = useState(false);
|
const [aec3Loading, setAec3Loading] = useState(false);
|
||||||
const aec3Ref = useRef<Aec3Instance | null>(null);
|
const aec3Ref = useRef<Aec3Instance | null>(null);
|
||||||
// Mirrors aec3Enabled but updates immediately, for startMic() calls made in
|
// Mirrors aec3Enabled but updates immediately, for startMic() calls made in
|
||||||
@@ -7507,6 +7549,25 @@ function AppInner() {
|
|||||||
localStorage.setItem(PUSH_TO_TALK_KEY, pushToTalk ? "1" : "0");
|
localStorage.setItem(PUSH_TO_TALK_KEY, pushToTalk ? "1" : "0");
|
||||||
}, [pushToTalk]);
|
}, [pushToTalk]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
continuousRef.current = continuous;
|
||||||
|
if (micCaptureRef.current) micCaptureRef.current.continuous = continuous;
|
||||||
|
localStorage.setItem(CONTINUOUS_KEY, continuous ? "1" : "0");
|
||||||
|
}, [continuous]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
typingAttenuationRef.current = typingAttenuation;
|
||||||
|
if (micCaptureRef.current) micCaptureRef.current.typingAttenuation = typingAttenuation;
|
||||||
|
localStorage.setItem(TYPING_ATTENUATION_KEY, typingAttenuation ? "1" : "0");
|
||||||
|
if (!typingAttenuation) return;
|
||||||
|
const onKeyDown = (e: KeyboardEvent) => {
|
||||||
|
// The push-to-talk key is not typing.
|
||||||
|
if (e.code !== pttBinding?.code) micCaptureRef.current?.noteTyping();
|
||||||
|
};
|
||||||
|
window.addEventListener("keydown", onKeyDown, true);
|
||||||
|
return () => window.removeEventListener("keydown", onKeyDown, true);
|
||||||
|
}, [typingAttenuation, pttBinding]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
pttPressedRef.current = pttPressed;
|
pttPressedRef.current = pttPressed;
|
||||||
if (micCaptureRef.current) micCaptureRef.current.pttPressed = pttPressed;
|
if (micCaptureRef.current) micCaptureRef.current.pttPressed = pttPressed;
|
||||||
@@ -7564,6 +7625,20 @@ function AppInner() {
|
|||||||
localStorage.setItem(PLAYBACK_VOLUME_KEY, String(playbackVolume));
|
localStorage.setItem(PLAYBACK_VOLUME_KEY, String(playbackVolume));
|
||||||
}, [playbackVolume]);
|
}, [playbackVolume]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
audioPlayerRef.current?.setAutoVolume(autoVolume);
|
||||||
|
localStorage.setItem(AUTO_VOLUME_KEY, autoVolume ? "1" : "0");
|
||||||
|
}, [autoVolume]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem(OWN_MIC_CLICKS_KEY, ownMicClicks ? "1" : "0");
|
||||||
|
}, [ownMicClicks]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
otherMicClicksRef.current = otherMicClicks;
|
||||||
|
localStorage.setItem(OTHER_MIC_CLICKS_KEY, otherMicClicks ? "1" : "0");
|
||||||
|
}, [otherMicClicks]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
localStorage.setItem(NOISE_SUPPRESSION_KEY, noiseSuppressionEnabled ? "1" : "0");
|
localStorage.setItem(NOISE_SUPPRESSION_KEY, noiseSuppressionEnabled ? "1" : "0");
|
||||||
}, [noiseSuppressionEnabled]);
|
}, [noiseSuppressionEnabled]);
|
||||||
@@ -7698,6 +7773,7 @@ function AppInner() {
|
|||||||
// that existed at the time - a fresh one (first use, or after
|
// that existed at the time - a fresh one (first use, or after
|
||||||
// disposeAudioIfIdle) has to be brought up to the current settings.
|
// disposeAudioIfIdle) has to be brought up to the current settings.
|
||||||
player.setVolume(playbackVolume);
|
player.setVolume(playbackVolume);
|
||||||
|
player.setAutoVolume(autoVolume);
|
||||||
if (outputDeviceId) {
|
if (outputDeviceId) {
|
||||||
player.setOutputDevice(outputDeviceId).catch((error: Error) =>
|
player.setOutputDevice(outputDeviceId).catch((error: Error) =>
|
||||||
appendLog({ text: `Output device error: ${error.message}`, kind: "error" }),
|
appendLog({ text: `Output device error: ${error.message}`, kind: "error" }),
|
||||||
@@ -7791,7 +7867,8 @@ function AppInner() {
|
|||||||
setPokes(parked.pokes);
|
setPokes(parked.pokes);
|
||||||
setActiveFavoriteId(parked.favoriteId);
|
setActiveFavoriteId(parked.favoriteId);
|
||||||
setActiveTab(parked.chatTab);
|
setActiveTab(parked.chatTab);
|
||||||
setTalkers(new Set(parked.talkers));
|
talkersRef.current = new Set(parked.talkers);
|
||||||
|
setTalkers(talkersRef.current);
|
||||||
setWhisperChannelIds(new Set(parked.whisperChannelIds));
|
setWhisperChannelIds(new Set(parked.whisperChannelIds));
|
||||||
setWhisperClientIds(new Set(parked.whisperClientIds));
|
setWhisperClientIds(new Set(parked.whisperClientIds));
|
||||||
setWhisperLog(parked.whisperLog);
|
setWhisperLog(parked.whisperLog);
|
||||||
@@ -7833,7 +7910,8 @@ function AppInner() {
|
|||||||
setPmThreads({});
|
setPmThreads({});
|
||||||
setPokes([]);
|
setPokes([]);
|
||||||
setActiveTab("channel");
|
setActiveTab("channel");
|
||||||
setTalkers(new Set());
|
talkersRef.current = new Set();
|
||||||
|
setTalkers(talkersRef.current);
|
||||||
setWhisperChannelIds(new Set());
|
setWhisperChannelIds(new Set());
|
||||||
setWhisperClientIds(new Set());
|
setWhisperClientIds(new Set());
|
||||||
setWhisperLog([]);
|
setWhisperLog([]);
|
||||||
@@ -8195,9 +8273,18 @@ function AppInner() {
|
|||||||
// Audio only for the active session tab.
|
// Audio only for the active session tab.
|
||||||
if (!outputMutedRef.current) audioPlayerRef.current?.playFrame(data.pcm);
|
if (!outputMutedRef.current) audioPlayerRef.current?.playFrame(data.pcm);
|
||||||
break;
|
break;
|
||||||
case "talkers":
|
case "talkers": {
|
||||||
setTalkers(new Set<number>(data.clients));
|
const next = new Set<number>(data.clients);
|
||||||
|
const prev = talkersRef.current;
|
||||||
|
if (otherMicClicksRef.current && !outputMutedRef.current) {
|
||||||
|
// One click per update, even if several people start at once.
|
||||||
|
if ([...next].some((id) => !prev.has(id))) void playSound("micClickOn");
|
||||||
|
else if ([...prev].some((id) => !next.has(id))) void playSound("micClickOff");
|
||||||
|
}
|
||||||
|
talkersRef.current = next;
|
||||||
|
setTalkers(next);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "reconnecting":
|
case "reconnecting":
|
||||||
// The gateway lost the TS server and is reconnecting by itself.
|
// The gateway lost the TS server and is reconnecting by itself.
|
||||||
appendLog({ text: t("log.serverReconnecting"), kind: "error" });
|
appendLog({ text: t("log.serverReconnecting"), kind: "error" });
|
||||||
@@ -9297,6 +9384,8 @@ function AppInner() {
|
|||||||
micCaptureRef.current?.stop();
|
micCaptureRef.current?.stop();
|
||||||
micCaptureRef.current = mic;
|
micCaptureRef.current = mic;
|
||||||
mic.pushToTalk = pushToTalkRef.current;
|
mic.pushToTalk = pushToTalkRef.current;
|
||||||
|
mic.continuous = continuousRef.current;
|
||||||
|
mic.typingAttenuation = typingAttenuationRef.current;
|
||||||
mic.pttPressed = pttPressedRef.current;
|
mic.pttPressed = pttPressedRef.current;
|
||||||
mic.setExtraAudio(tabAudioRef.current);
|
mic.setExtraAudio(tabAudioRef.current);
|
||||||
setMicOn(true);
|
setMicOn(true);
|
||||||
@@ -10367,10 +10456,17 @@ function AppInner() {
|
|||||||
const isAway = ownClient?.away ?? false;
|
const isAway = ownClient?.away ?? false;
|
||||||
const inputMuted = ownClient?.inputMuted ?? false;
|
const inputMuted = ownClient?.inputMuted ?? false;
|
||||||
const outputMuted = ownClient?.outputMuted ?? false;
|
const outputMuted = ownClient?.outputMuted ?? false;
|
||||||
const displayTalkers =
|
const selfTalking = Boolean(selfActive && !inputMuted && ownClient?.hasTalkPower);
|
||||||
selfActive && !inputMuted && ownClient?.hasTalkPower
|
const displayTalkers = selfTalking && ownClient ? new Set(talkers).add(ownClient.id) : talkers;
|
||||||
? new Set(talkers).add(ownClient.id)
|
const selfTalkingSeenRef = useRef(false);
|
||||||
: talkers;
|
useEffect(() => {
|
||||||
|
// Skip the initial render so opening the client doesn't click.
|
||||||
|
if (!selfTalkingSeenRef.current) {
|
||||||
|
selfTalkingSeenRef.current = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ownMicClicks && !outputMuted) void playSound(selfTalking ? "micClickOn" : "micClickOff");
|
||||||
|
}, [selfTalking]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
const showServerQueryClients =
|
const showServerQueryClients =
|
||||||
activeFavoriteId != null &&
|
activeFavoriteId != null &&
|
||||||
favorites.some((f) => f.id === activeFavoriteId && f.showServerQueryClients);
|
favorites.some((f) => f.id === activeFavoriteId && f.showServerQueryClients);
|
||||||
@@ -11157,7 +11253,7 @@ function AppInner() {
|
|||||||
>
|
>
|
||||||
🗣️
|
🗣️
|
||||||
</button>
|
</button>
|
||||||
) : (
|
) : continuous ? null : (
|
||||||
<label className="ts-icon-slider" title={t("toolbar.vadSensitivity")}>
|
<label className="ts-icon-slider" title={t("toolbar.vadSensitivity")}>
|
||||||
🎚️
|
🎚️
|
||||||
<input
|
<input
|
||||||
@@ -11608,6 +11704,12 @@ function AppInner() {
|
|||||||
onRefreshOutputDevices: refreshOutputDevices,
|
onRefreshOutputDevices: refreshOutputDevices,
|
||||||
playbackVolume,
|
playbackVolume,
|
||||||
onPlaybackVolumeChange: setPlaybackVolume,
|
onPlaybackVolumeChange: setPlaybackVolume,
|
||||||
|
autoVolume,
|
||||||
|
onAutoVolumeChange: setAutoVolume,
|
||||||
|
ownMicClicks,
|
||||||
|
onOwnMicClicksChange: setOwnMicClicks,
|
||||||
|
otherMicClicks,
|
||||||
|
onOtherMicClicksChange: setOtherMicClicks,
|
||||||
onPlayTestTone: handlePlayTestTone,
|
onPlayTestTone: handlePlayTestTone,
|
||||||
inputDevices,
|
inputDevices,
|
||||||
inputDeviceId,
|
inputDeviceId,
|
||||||
@@ -11622,6 +11724,10 @@ function AppInner() {
|
|||||||
vadHangover,
|
vadHangover,
|
||||||
onVadHangoverChange: setVadHangover,
|
onVadHangoverChange: setVadHangover,
|
||||||
pushToTalk,
|
pushToTalk,
|
||||||
|
continuous,
|
||||||
|
onContinuousChange: setContinuous,
|
||||||
|
typingAttenuation,
|
||||||
|
onTypingAttenuationChange: setTypingAttenuation,
|
||||||
onPushToTalkChange: setPushToTalk,
|
onPushToTalkChange: setPushToTalk,
|
||||||
pttBinding,
|
pttBinding,
|
||||||
onPttBindingChange: setPttBinding,
|
onPttBindingChange: setPttBinding,
|
||||||
|
|||||||
@@ -667,6 +667,8 @@
|
|||||||
"sounds.event.message": "Přijata zpráva",
|
"sounds.event.message": "Přijata zpráva",
|
||||||
"sounds.event.poke": "Přijato šťouchnutí",
|
"sounds.event.poke": "Přijato šťouchnutí",
|
||||||
"sounds.event.mute": "Přepnutí ztlumení",
|
"sounds.event.mute": "Přepnutí ztlumení",
|
||||||
|
"sounds.event.micClickOn": "Kliknutí mikrofonu zap.",
|
||||||
|
"sounds.event.micClickOff": "Kliknutí mikrofonu vyp.",
|
||||||
"sounds.default": "Výchozí",
|
"sounds.default": "Výchozí",
|
||||||
"sounds.custom": "Vlastní soubor: {name}",
|
"sounds.custom": "Vlastní soubor: {name}",
|
||||||
"sounds.test": "▶ Test",
|
"sounds.test": "▶ Test",
|
||||||
|
|||||||
@@ -667,6 +667,8 @@
|
|||||||
"sounds.event.message": "Nachricht empfangen",
|
"sounds.event.message": "Nachricht empfangen",
|
||||||
"sounds.event.poke": "Anstupsen erhalten",
|
"sounds.event.poke": "Anstupsen erhalten",
|
||||||
"sounds.event.mute": "Stummschaltung umgeschaltet",
|
"sounds.event.mute": "Stummschaltung umgeschaltet",
|
||||||
|
"sounds.event.micClickOn": "Mikro Klick an",
|
||||||
|
"sounds.event.micClickOff": "Mikro Klick aus",
|
||||||
"sounds.default": "Standard",
|
"sounds.default": "Standard",
|
||||||
"sounds.custom": "Eigene Datei: {name}",
|
"sounds.custom": "Eigene Datei: {name}",
|
||||||
"sounds.test": "▶ Testen",
|
"sounds.test": "▶ Testen",
|
||||||
|
|||||||
@@ -667,6 +667,8 @@
|
|||||||
"sounds.event.message": "Message received",
|
"sounds.event.message": "Message received",
|
||||||
"sounds.event.poke": "Poke received",
|
"sounds.event.poke": "Poke received",
|
||||||
"sounds.event.mute": "Mute toggled",
|
"sounds.event.mute": "Mute toggled",
|
||||||
|
"sounds.event.micClickOn": "Mic click on",
|
||||||
|
"sounds.event.micClickOff": "Mic click off",
|
||||||
"sounds.default": "Default",
|
"sounds.default": "Default",
|
||||||
"sounds.custom": "Custom file: {name}",
|
"sounds.custom": "Custom file: {name}",
|
||||||
"sounds.test": "▶ Test",
|
"sounds.test": "▶ Test",
|
||||||
|
|||||||
@@ -666,6 +666,8 @@
|
|||||||
"sounds.event.message": "پیام دریافت شد",
|
"sounds.event.message": "پیام دریافت شد",
|
||||||
"sounds.event.poke": "سقلمه دریافت شد",
|
"sounds.event.poke": "سقلمه دریافت شد",
|
||||||
"sounds.event.mute": "تغییر حالت بیصدا",
|
"sounds.event.mute": "تغییر حالت بیصدا",
|
||||||
|
"sounds.event.micClickOn": "کلیک میکروفون روشن",
|
||||||
|
"sounds.event.micClickOff": "کلیک میکروفون خاموش",
|
||||||
"sounds.default": "پیشفرض",
|
"sounds.default": "پیشفرض",
|
||||||
"sounds.custom": "فایل سفارشی: {name}",
|
"sounds.custom": "فایل سفارشی: {name}",
|
||||||
"sounds.test": "▶ آزمایش",
|
"sounds.test": "▶ آزمایش",
|
||||||
|
|||||||
@@ -512,6 +512,8 @@
|
|||||||
"sounds.event.message": "收到消息",
|
"sounds.event.message": "收到消息",
|
||||||
"sounds.event.poke": "收到戳一戳",
|
"sounds.event.poke": "收到戳一戳",
|
||||||
"sounds.event.mute": "切换静音",
|
"sounds.event.mute": "切换静音",
|
||||||
|
"sounds.event.micClickOn": "麦克风开启提示音",
|
||||||
|
"sounds.event.micClickOff": "麦克风关闭提示音",
|
||||||
"sounds.default": "默认",
|
"sounds.default": "默认",
|
||||||
"sounds.custom": "自定义文件:{name}",
|
"sounds.custom": "自定义文件:{name}",
|
||||||
"sounds.test": "▶ 测试",
|
"sounds.test": "▶ 测试",
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ const EVENT_KEYWORDS: Record<SoundEventId, string[]> = {
|
|||||||
message: ["textmessagereceived", "chatmessage", "newmessage", "message"],
|
message: ["textmessagereceived", "chatmessage", "newmessage", "message"],
|
||||||
poke: ["gotpoked", "poke"],
|
poke: ["gotpoked", "poke"],
|
||||||
mute: ["micmuted", "microphonemuted", "micactivated", "microphoneactivated"],
|
mute: ["micmuted", "microphonemuted", "micactivated", "microphoneactivated"],
|
||||||
|
micClickOn: ["micclickon"],
|
||||||
|
micClickOff: ["micclickoff"],
|
||||||
};
|
};
|
||||||
|
|
||||||
function normalize(filename: string): string {
|
function normalize(filename: string): string {
|
||||||
|
|||||||
+29
-2
@@ -1,6 +1,25 @@
|
|||||||
export type SoundEventId = "connect" | "disconnect" | "clientJoin" | "clientLeave" | "message" | "poke" | "mute";
|
export type SoundEventId =
|
||||||
|
| "connect"
|
||||||
|
| "disconnect"
|
||||||
|
| "clientJoin"
|
||||||
|
| "clientLeave"
|
||||||
|
| "message"
|
||||||
|
| "poke"
|
||||||
|
| "mute"
|
||||||
|
| "micClickOn"
|
||||||
|
| "micClickOff";
|
||||||
|
|
||||||
export const SOUND_EVENTS: SoundEventId[] = ["connect", "disconnect", "clientJoin", "clientLeave", "message", "poke", "mute"];
|
export const SOUND_EVENTS: SoundEventId[] = [
|
||||||
|
"connect",
|
||||||
|
"disconnect",
|
||||||
|
"clientJoin",
|
||||||
|
"clientLeave",
|
||||||
|
"message",
|
||||||
|
"poke",
|
||||||
|
"mute",
|
||||||
|
"micClickOn",
|
||||||
|
"micClickOff",
|
||||||
|
];
|
||||||
|
|
||||||
/** "ide" swaps the default chimes for synthetic terminal blips (Command Center layout). */
|
/** "ide" swaps the default chimes for synthetic terminal blips (Command Center layout). */
|
||||||
type SoundStyle = "classic" | "ide";
|
type SoundStyle = "classic" | "ide";
|
||||||
@@ -215,6 +234,10 @@ function synthNotes(event: SoundEventId): SynthNote[] {
|
|||||||
];
|
];
|
||||||
case "mute":
|
case "mute":
|
||||||
return [{ delay: 0, freq: 660, duration: 0.06, gain: 0.3 }];
|
return [{ delay: 0, freq: 660, duration: 0.06, gain: 0.3 }];
|
||||||
|
case "micClickOn":
|
||||||
|
return [{ delay: 0, freq: 1400, duration: 0.03, gain: 0.15 }];
|
||||||
|
case "micClickOff":
|
||||||
|
return [{ delay: 0, freq: 900, duration: 0.03, gain: 0.15 }];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,6 +270,10 @@ function ideNotes(event: SoundEventId): SynthNote[] {
|
|||||||
];
|
];
|
||||||
case "mute":
|
case "mute":
|
||||||
return [{ delay: 0, freq: 300, endFreq: 50, duration: 0.04, gain: 0.15, type: "square" }];
|
return [{ delay: 0, freq: 300, endFreq: 50, duration: 0.04, gain: 0.15, type: "square" }];
|
||||||
|
case "micClickOn":
|
||||||
|
return [{ delay: 0, freq: 1600, duration: 0.02, gain: 0.08, type: "square" }];
|
||||||
|
case "micClickOff":
|
||||||
|
return [{ delay: 0, freq: 1000, duration: 0.02, gain: 0.08, type: "square" }];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+46
-5
@@ -87,6 +87,12 @@ export class MicCapture {
|
|||||||
/** Push-to-talk: send while `pttPressed` instead of voice activation. */
|
/** Push-to-talk: send while `pttPressed` instead of voice activation. */
|
||||||
pushToTalk = false;
|
pushToTalk = false;
|
||||||
pttPressed = false;
|
pttPressed = false;
|
||||||
|
/** Send all the time, no voice activation (ignored while pushToTalk). */
|
||||||
|
continuous = false;
|
||||||
|
/** Damp the mic right after a keystroke, so typing doesn't trigger
|
||||||
|
* voice activation and is quieter while talking. See noteTyping(). */
|
||||||
|
typingAttenuation = false;
|
||||||
|
private typingUntil = 0;
|
||||||
|
|
||||||
constructor(context: AudioContext, options: MicCaptureOptions) {
|
constructor(context: AudioContext, options: MicCaptureOptions) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@@ -139,6 +145,10 @@ export class MicCapture {
|
|||||||
this.aec3.process(this.aec3Out, captureIn);
|
this.aec3.process(this.aec3Out, captureIn);
|
||||||
input = this.aec3Out[0];
|
input = this.aec3Out[0];
|
||||||
}
|
}
|
||||||
|
if (this.typingAttenuation && this.context.currentTime < this.typingUntil) {
|
||||||
|
// Copy first: `raw` is the input buffer, not ours to change.
|
||||||
|
input = input.map((v) => v * 0.1);
|
||||||
|
}
|
||||||
// Mirrors the (possibly AEC3-cancelled) signal to the output buffer, so
|
// Mirrors the (possibly AEC3-cancelled) signal to the output buffer, so
|
||||||
// setMonitoring() below can tap what's actually being sent rather than
|
// setMonitoring() below can tap what's actually being sent rather than
|
||||||
// the raw pre-cancellation mic feed - a self-test through the raw feed
|
// the raw pre-cancellation mic feed - a self-test through the raw feed
|
||||||
@@ -152,7 +162,7 @@ export class MicCapture {
|
|||||||
|
|
||||||
const now = this.context.currentTime;
|
const now = this.context.currentTime;
|
||||||
if (rms >= this.threshold) this.activeUntil = now + this.hangoverSeconds;
|
if (rms >= this.threshold) this.activeUntil = now + this.hangoverSeconds;
|
||||||
const talking = this.pushToTalk ? this.pttPressed : now < this.activeUntil;
|
const talking = this.pushToTalk ? this.pttPressed : this.continuous || now < this.activeUntil;
|
||||||
// Shared audio (music, a video) has its own pauses; keep sending throughout.
|
// Shared audio (music, a video) has its own pauses; keep sending throughout.
|
||||||
const shouldBeActive = this.extra !== null || talking;
|
const shouldBeActive = this.extra !== null || talking;
|
||||||
if (shouldBeActive !== this.active) {
|
if (shouldBeActive !== this.active) {
|
||||||
@@ -201,6 +211,11 @@ export class MicCapture {
|
|||||||
this.silence.connect(this.context.destination);
|
this.silence.connect(this.context.destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Call on every keystroke; with typingAttenuation on, the next ~0.2 s are damped. */
|
||||||
|
noteTyping(): void {
|
||||||
|
this.typingUntil = this.context.currentTime + 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
/** Mixes a second stream (e.g. a shared tab's audio) into what is sent, or
|
/** Mixes a second stream (e.g. a shared tab's audio) into what is sent, or
|
||||||
* removes it with null. The caller keeps ownership of the stream. */
|
* removes it with null. The caller keeps ownership of the stream. */
|
||||||
setExtraAudio(stream: MediaStream | null): void {
|
setExtraAudio(stream: MediaStream | null): void {
|
||||||
@@ -357,6 +372,10 @@ export class AudioPlayer {
|
|||||||
private destination: MediaStreamAudioDestinationNode | null = null;
|
private destination: MediaStreamAudioDestinationNode | null = null;
|
||||||
private element: SinkableElement | null = null;
|
private element: SinkableElement | null = null;
|
||||||
private gain: GainNode;
|
private gain: GainNode;
|
||||||
|
// Voice frames only (not test tone, clicks or mic monitoring), so the
|
||||||
|
// leveler can sit between them and the volume gain.
|
||||||
|
private voice: GainNode;
|
||||||
|
private leveler: DynamicsCompressorNode;
|
||||||
private context: AudioContext;
|
private context: AudioContext;
|
||||||
private aecTap: ScriptProcessorNode | null = null;
|
private aecTap: ScriptProcessorNode | null = null;
|
||||||
private aecSink: GainNode | null = null;
|
private aecSink: GainNode | null = null;
|
||||||
@@ -364,6 +383,18 @@ export class AudioPlayer {
|
|||||||
constructor(context: AudioContext) {
|
constructor(context: AudioContext) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.gain = context.createGain();
|
this.gain = context.createGain();
|
||||||
|
this.voice = context.createGain();
|
||||||
|
// "Automatic volume leveling": evens out loud and quiet speakers. Browsers
|
||||||
|
// add their own makeup gain, so quiet voices come up too.
|
||||||
|
// ponytail: one compressor for the whole mix, not per speaker like TS3.
|
||||||
|
this.leveler = context.createDynamicsCompressor();
|
||||||
|
this.leveler.threshold.value = -30;
|
||||||
|
this.leveler.knee.value = 10;
|
||||||
|
this.leveler.ratio.value = 4;
|
||||||
|
this.leveler.attack.value = 0.005;
|
||||||
|
this.leveler.release.value = 0.3;
|
||||||
|
this.leveler.connect(this.gain);
|
||||||
|
this.voice.connect(this.gain);
|
||||||
if (!("setSinkId" in HTMLMediaElement.prototype)) {
|
if (!("setSinkId" in HTMLMediaElement.prototype)) {
|
||||||
this.gain.connect(context.destination);
|
this.gain.connect(context.destination);
|
||||||
return;
|
return;
|
||||||
@@ -398,7 +429,7 @@ export class AudioPlayer {
|
|||||||
|
|
||||||
const source = this.context.createBufferSource();
|
const source = this.context.createBufferSource();
|
||||||
source.buffer = buffer;
|
source.buffer = buffer;
|
||||||
source.connect(this.gain);
|
source.connect(this.voice);
|
||||||
|
|
||||||
const now = this.context.currentTime;
|
const now = this.context.currentTime;
|
||||||
if (this.nextTime < now + 0.02) {
|
if (this.nextTime < now + 0.02) {
|
||||||
@@ -419,6 +450,11 @@ export class AudioPlayer {
|
|||||||
this.gain.gain.value = gain;
|
this.gain.gain.value = gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setAutoVolume(enabled: boolean): void {
|
||||||
|
this.voice.disconnect();
|
||||||
|
this.voice.connect(enabled ? this.leveler : this.gain);
|
||||||
|
}
|
||||||
|
|
||||||
/** The node all voice/test audio ultimately reaches - use as a mic-monitoring target so it also respects volume/output device. */
|
/** The node all voice/test audio ultimately reaches - use as a mic-monitoring target so it also respects volume/output device. */
|
||||||
getInputNode(): AudioNode {
|
getInputNode(): AudioNode {
|
||||||
return this.gain;
|
return this.gain;
|
||||||
@@ -430,12 +466,15 @@ export class AudioPlayer {
|
|||||||
osc.type = "sine";
|
osc.type = "sine";
|
||||||
osc.frequency.value = 440;
|
osc.frequency.value = 440;
|
||||||
const toneGain = this.context.createGain();
|
const toneGain = this.context.createGain();
|
||||||
toneGain.gain.value = 0.3;
|
const now = this.context.currentTime;
|
||||||
|
// Soft fade in and decay instead of a flat, hard-edged beep.
|
||||||
|
toneGain.gain.setValueAtTime(0, now);
|
||||||
|
toneGain.gain.linearRampToValueAtTime(0.15, now + 0.03);
|
||||||
|
toneGain.gain.exponentialRampToValueAtTime(0.0001, now + 0.8);
|
||||||
osc.connect(toneGain);
|
osc.connect(toneGain);
|
||||||
toneGain.connect(this.gain);
|
toneGain.connect(this.gain);
|
||||||
const now = this.context.currentTime;
|
|
||||||
osc.start(now);
|
osc.start(now);
|
||||||
osc.stop(now + 0.6);
|
osc.stop(now + 0.85);
|
||||||
osc.onended = () => {
|
osc.onended = () => {
|
||||||
osc.disconnect();
|
osc.disconnect();
|
||||||
toneGain.disconnect();
|
toneGain.disconnect();
|
||||||
@@ -487,6 +526,8 @@ export class AudioPlayer {
|
|||||||
|
|
||||||
dispose(): void {
|
dispose(): void {
|
||||||
this.detachAecRenderTap();
|
this.detachAecRenderTap();
|
||||||
|
this.voice.disconnect();
|
||||||
|
this.leveler.disconnect();
|
||||||
this.gain.disconnect();
|
this.gain.disconnect();
|
||||||
if (!this.element) return;
|
if (!this.element) return;
|
||||||
this.element.pause();
|
this.element.pause();
|
||||||
|
|||||||
Reference in new issue
Block a user