Skip to content

Commit

Permalink
Possible fix for bug on mobile devices with audio playing through ear…
Browse files Browse the repository at this point in the history
… speaker.
  • Loading branch information
BadgerHobbs committed Nov 9, 2023
1 parent e788469 commit ccbbe46
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions js/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Assistant {
systemMessage;
state;
mediaRecorder;
mediaStream;

/**
* Initialise Assistant object.
Expand Down Expand Up @@ -124,18 +125,20 @@ class Assistant {
if (this.state === State.LISTENING) {
this.setState(State.THINKING);
this.mediaRecorder.stop();
this.mediaStream.getTracks().forEach((track) => track.stop());
this.mediaStream = null;
}

// Else if state waiting set state to listenind and start recording
// Else if state is waiting, set state to listening and start recording
else if (this.state === State.WAITING) {
this.setState(State.LISTENING);

// Create media stream and recorder to record audio
const mediaStream = await navigator.mediaDevices.getUserMedia({
this.mediaStream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: false,
});
this.mediaRecorder = new MediaRecorder(mediaStream);
this.mediaRecorder = new MediaRecorder(this.mediaStream);

let recordedChunks = [];

Expand Down

0 comments on commit ccbbe46

Please sign in to comment.