Skip to content

Commit 9630d46

Browse files
committed
fix: try to ask permition before playing audio
1 parent 99acbf2 commit 9630d46

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

custom/composables/useAgentAudio.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type StreamingAudioState = {
1616

1717
let standByAudio: HTMLAudioElement | null = null;
1818
let isStandByAudioPlaying = false;
19-
function playStandByAudio() {
19+
async function playStandByAudio() {
2020
if (!standByAudio) {
2121
standByAudio = new Audio(`/plugins/AdminForthAgentPlugin/agentAudio/agent-processing.mp3`);
2222
standByAudio.addEventListener('ended', () => {
@@ -26,7 +26,7 @@ function playStandByAudio() {
2626
});
2727
}
2828
standByAudio.currentTime = 0;
29-
standByAudio.play()
29+
await standByAudio.play();
3030
isStandByAudioPlaying = true;
3131
}
3232

@@ -215,7 +215,7 @@ export const useAgentAudio = defineStore('agentAudio', () => {
215215
}
216216
}
217217

218-
function setIsPlaying(value: boolean) {
218+
async function setIsPlaying(value: boolean) {
219219
isPlaying = value;
220220

221221
if (!currentAudio) {
@@ -228,7 +228,7 @@ export const useAgentAudio = defineStore('agentAudio', () => {
228228
return;
229229
}
230230
agentAudioMode.value = 'playingAgentResponse';
231-
void currentAudio.play().catch((error) => {
231+
await void currentAudio.play().catch((error) => {
232232
console.error('Failed to play audio:', error);
233233
});
234234
}

0 commit comments

Comments
 (0)