diff --git a/app/MindWork AI Studio/wwwroot/app.js b/app/MindWork AI Studio/wwwroot/app.js index 8a4e036d..6c1ebaf4 100644 --- a/app/MindWork AI Studio/wwwroot/app.js +++ b/app/MindWork AI Studio/wwwroot/app.js @@ -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); } }; diff --git a/app/MindWork AI Studio/wwwroot/changelog/v26.1.2.md b/app/MindWork AI Studio/wwwroot/changelog/v26.1.2.md index d6c034ea..bc18a68a 100644 --- a/app/MindWork AI Studio/wwwroot/changelog/v26.1.2.md +++ b/app/MindWork AI Studio/wwwroot/changelog/v26.1.2.md @@ -3,4 +3,5 @@ - Improved error handling for model loading in provider dialogs (LLMs, embeddings, transcriptions). - Fixed a logging bug that prevented log events from being recorded in some cases. - Fixed a bug that allowed adding a provider without selecting a model. -- Fixed a bug with local transcription providers by handling errors correctly when the local provider is unavailable. \ No newline at end of file +- Fixed a bug with local transcription providers by handling errors correctly when the local provider is unavailable. +- 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 wouldn’t resume as expected. This behavior is now fixed. \ No newline at end of file