Improved sound effect handling with shared audio context

This commit is contained in:
Thorsten Sommer 2026-01-18 14:20:09 +01:00
parent 5f18cbe2bf
commit 06a7cfb0fe
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 35 additions and 7 deletions

View File

@ -27,14 +27,41 @@ window.scrollToBottom = function(element) {
element.scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'nearest' });
}
window.playSound = function(soundPath) {
// Shared audio context for sound effects (Web Audio API does not register with Media Session):
let soundEffectContext = null;
const soundEffectCache = new Map();
window.playSound = async function(soundPath) {
try {
const audio = new Audio(soundPath);
audio.play().catch(error => {
console.warn('Failed to play sound effect:', error);
});
// Create or reuse the audio context:
if (!soundEffectContext || soundEffectContext.state === 'closed') {
soundEffectContext = new (window.AudioContext || window.webkitAudioContext)();
}
// Resume if suspended (browser autoplay policy):
if (soundEffectContext.state === 'suspended') {
await soundEffectContext.resume();
}
// Check the cache for already decoded audio:
let audioBuffer = soundEffectCache.get(soundPath);
if (!audioBuffer) {
// Fetch and decode the audio file:
const response = await fetch(soundPath);
const arrayBuffer = await response.arrayBuffer();
audioBuffer = await soundEffectContext.decodeAudioData(arrayBuffer);
soundEffectCache.set(soundPath, audioBuffer);
}
// Create a new source node and play:
const source = soundEffectContext.createBufferSource();
source.buffer = audioBuffer;
source.connect(soundEffectContext.destination);
source.start(0);
} catch (error) {
console.warn('Error creating audio element:', error);
console.warn('Failed to play sound effect:', error);
}
};

View File

@ -1,3 +1,4 @@
# v26.1.2, build 232 (2026-01-xx xx:xx UTC)
- Added the option to hide specific assistants by configuration plugins. This is useful for enterprise environments in organizations.
- Fixed a logging bug that prevented log events from being recorded in some cases.
- Fixed a logging bug that prevented log events from being recorded in some cases.
- Fixed a bug affecting the transcription preview: previously, when you stopped music or other media, recorded or dictated text, and then tried to resume playback, the media wouldnt resume as expected. This behavior is now fixed.