Enhanced audio out

This commit is contained in:
Saifeddine ALOUI 2023-04-14 23:15:54 +02:00
parent b6f6721ded
commit 494ced0620
4 changed files with 30 additions and 16 deletions

View File

@ -7,6 +7,9 @@ echo %modelPath%
echo Converting the model to the new format...
if not exist tmp\llama.cpp git clone https://github.com/ggerganov/llama.cpp.git tmp\llama.cpp
cd tmp\llama.cpp
git checkout 0f07cacb05f49704d35a39aa27cfd4b419eb6f8d
git checkout 6c248707f51c8a50f7792e7f7787ec481881db88
cd ../..
pwd
move /y "%filename%" "%filename%.original"
python tmp\llama.cpp\migrate-ggml-2023-03-30-pr613.py "%filename%.original" "%filename%"
echo Converting ...
python tmp\llama.cpp\migrate-ggml-2023-03-30-pr613.py "%newname%" "%filename%"

View File

@ -0,0 +1,12 @@
@echo off
REM put the model to ../models/alpaca as well as the tokenizer
set filename=../models/alpaca
set tokenizer=../models/alpaca/alpaca_tokenizer.model
echo %modelPath%
echo Converting the model to the new format...
if not exist tmp\llama.cpp git clone https://github.com/ggerganov/llama.cpp.git tmp\llama.cpp
cd tmp\llama.cpp
git checkout 6c248707f51c8a50f7792e7f7787ec481881db88
cd ../..
echo Converting ...
python tmp\llama.cpp\convert-gpt4all-to-ggml.py "%filename%" "%tokenizer%"

View File

@ -77,19 +77,19 @@ if (!userAgent.match(/firefox|fxios/i)) {
};
}
function attachAudio_modules(div) {
if (div.parentNode.getElementsByClassName("audio-out-button").length > 0) {
function attachAudio_modules(div, container) {
if (container.getElementsByClassName("audio-out-button").length > 0) {
return;
}
const audio_out_button = document.createElement("button");
audio_out_button.id = "audio-out-button";
audio_out_button.classList.add("audio_btn");
audio_out_button.classList.add("audio_btn",'bg-green-500', 'hover:bg-green-700', 'text-white', 'font-bold', 'py-0', 'px-0', 'rounded', "w-10", "h-10");
audio_out_button.innerHTML = "🕪";
div.classList.add("flex-1");
audio_out_button.classList.add("audio-out-button");
div.appendChild(audio_out_button);
container.appendChild(audio_out_button);
function play_audio() {
console.log("Playing audio")
if (isSpeaking) {
audio_out_button.style.backgroundColor = "";
@ -98,7 +98,7 @@ if (!userAgent.match(/firefox|fxios/i)) {
isSpeaking = false;
} else {
isSpeaking = true;
text = audio_out_button.previousSibling.textContent;
text = div.textContent;
const selectedOption =
voice_select.selectedOptions[0].getAttribute("data-name");
@ -114,7 +114,9 @@ if (!userAgent.match(/firefox|fxios/i)) {
addListeners(audio_out_button, utterThis);
synth.speak(utterThis);
} else {
console.log("Not native")
texts = splitString(text, 200);
console.log(`Text to say ${texts}`)
texts.forEach((text) => {
const utterThis = new SpeechSynthesisUtterance(text);
utterThis.voice = selectedVoice;
@ -163,10 +165,6 @@ if (!userAgent.match(/firefox|fxios/i)) {
input.classList.add("flex-1");
audio_in_button.classList.add("ml-2");
//wrapper.appendChild(audio_in_button);
//input.parentNode.parentNode.insertBefore(wrapper, input);
//input.parentNode.removeChild(input);
//wrapper.appendChild(input);
audio_in_button.addEventListener("click", () => {
if (isStarted) {

View File

@ -298,6 +298,11 @@ function addMessage(sender, message, id, rank = 0, can_edit = false) {
buttonsContainer.appendChild(rank_up);
buttonsContainer.appendChild(rank_down);
messageElement.appendChild(buttonsContainer);
// Dirty fix for disabling speech synth for firefox browsers :()
if (!userAgent.match(/firefox|fxios/i)) {
attachAudio_modules(messageTextElement, buttonsContainer);
}
if (rank > 0) {
thumbUpBadge.innerText = `${rank}`
thumbDownBadge.innerText = ``
@ -321,10 +326,6 @@ function addMessage(sender, message, id, rank = 0, can_edit = false) {
chatWindow.appendChild(messageElement);
chatWindow.appendChild(hiddenElement);
// Dirty fix for disabling speech synth for firefox browsers :()
if (!userAgent.match(/firefox|fxios/i)) {
attachAudio_modules(messageTextElement);
}
// scroll to bottom of chat window
chatWindow.scrollTop = chatWindow.scrollHeight;