Skip to content

Commit

Permalink
Enhance graphics and status reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler committed Jun 7, 2024
1 parent 08d40eb commit 3d6a734
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 14 additions & 2 deletions core/http/static/talk.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function toggleRecording() {
}

async function startRecording() {
document.getElementById("recording").style.display = "block";
if (!navigator.mediaDevices) {
alert('MediaDevices API not supported!');
return;
Expand All @@ -60,25 +61,36 @@ async function startRecording() {
};
mediaRecorder.start();
recordButton.textContent = 'Stop Recording';
// add class bg-red-500 to recordButton
recordButton.classList.add("bg-gray-500");

isRecording = true;
}

function stopRecording() {
mediaRecorder.stop();
mediaRecorder.onstop = async () => {
document.getElementById("recording").style.display = "none";
document.getElementById("loader").style.display = "block";
const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
document.getElementById("statustext").textContent = "Processing audio...";
const transcript = await sendAudioToWhisper(audioBlob);
console.log("Transcript:", transcript)
console.log("Transcript:", transcript);
document.getElementById("statustext").textContent = "Seems you said: " + transcript+ ". Generating response...";
const responseText = await sendTextToChatGPT(transcript);
console.log("Response:", responseText)

console.log("Response:", responseText);
document.getElementById("statustext").textContent = "Response generated: '" + responseText + "'. Generating audio response...";

const ttsAudio = await getTextToSpeechAudio(responseText);
playAudioResponse(ttsAudio);

recordButton.textContent = 'Record';
// remove class bg-red-500 from recordButton
recordButton.classList.remove("bg-gray-500");
isRecording = false;
document.getElementById("loader").style.display = "none";
document.getElementById("statustext").textContent = "Press the record button to start recording.";
};
}

Expand Down
10 changes: 7 additions & 3 deletions core/http/views/talk.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
<div class="flex items-center justify-center">
<div class="w-full p-4 max-w-md border-t border-gray-700 ">
<div class="bg-gray-700 shadow-md rounded px-8 pt-6 pb-8 mb-4">
<div id="recording" class="" style="display: none;">
<i class="fa-solid fa-microphone animate-pulse text-red-700"></i>
<span class="text-white-700 text-sm font-bold mb-2">Recording... press "Stop recording" to stop</span>
</div>
<div id="loader" class="my-2 loader" style="display: none;"></div>

<div id="statustext" class="my-2 p-2 block text-white-700 text-sm font-bold mb-2" ></div>
<div class="mb-4" >
<label for="modelSelect" class="block text-white-700 text-sm font-bold mb-2">LLM Model:</label>
<select id="modelSelect"
Expand Down Expand Up @@ -88,8 +92,8 @@


<button id="recordButton"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline"
><i class="fa-solid fa-circle-up text-gray-300 absolute right-2 top-3 text-lg p-2"></i>Record</button>
class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline"
><i class="fa-solid fa-microphone pr-2"></i>Record</button>
<a id="resetButton"
class="inline-block align-baseline font-bold text-sm text-blue-500 hover:text-blue-800"
href="#"
Expand Down

0 comments on commit 3d6a734

Please sign in to comment.