Skip to content

Commit

Permalink
fix safari
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 committed Jun 3, 2024
1 parent 81c3b06 commit 9761f8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion recipes/llm-voice-assistant/web/public/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ window.onload = () => {
}
},
onComplete: async () => {
if (streamCalls <= 3) {
if (streamCalls <= 2) {
audioStream.play();
}
await audioStream.waitPlayback();
Expand Down
7 changes: 4 additions & 3 deletions recipes/llm-voice-assistant/web/src/audio_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AudioStream {
this._audioContext = new (window.AudioContext ||
// @ts-ignore
window.webKitAudioContext)({ sampleRate: sampleRate });
this._audioContext.resume();

this._audioGain = this._audioContext.createGain();
this._audioGain.gain.value = 1;
Expand All @@ -35,15 +36,15 @@ class AudioStream {
streamSource.buffer = this._audioBuffers.shift() ?? null;
streamSource.connect(this._audioGain);

streamSource.start();
this._isPlaying = true;

streamSource.onended = (): void => {
this._isPlaying = false;
if (this._audioBuffers.length > 0) {
this.play();
}
};

streamSource.start();
this._isPlaying = true;
}

public async waitPlayback(): Promise<void> {
Expand Down
6 changes: 3 additions & 3 deletions recipes/llm-voice-assistant/web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const init = async (

const detectionCallback = async (detection: PorcupineDetection): Promise<void> => {
if (detection.index === 0) {
await WebVoiceProcessor.unsubscribe(porcupine);
await WebVoiceProcessor.subscribe(cheetah);
await WebVoiceProcessor.unsubscribe(porcupine);
onDetection(detection);
}
};
Expand Down Expand Up @@ -114,9 +114,9 @@ const init = async (
streamCallback: async token => {
if (!stopPhrases.includes(token)) {
onText(token);
await mutex.acquire();
const release = await mutex.acquire();
const pcm = await stream.synthesize(token);
mutex.release();
release();
synthesized++;
if (pcm !== null) {
onStream(pcm);
Expand Down

0 comments on commit 9761f8f

Please sign in to comment.