Add soft French voice and contact saving
This commit is contained in:
@@ -323,7 +323,8 @@ async function sendVoiceBlob(blob) {
|
||||
async function handleAssistantResponse(data) {
|
||||
const reply = data.reply || "";
|
||||
addBubble(reply, "assistant");
|
||||
setStatus(data.emailSent ? "Email envoye" : "Pret", data.emailSent ? "live" : "idle");
|
||||
const status = data.emailSent ? "Email envoye" : data.contactSaved ? "Contact ajoute" : "Pret";
|
||||
setStatus(status, data.emailSent || data.contactSaved ? "live" : "idle");
|
||||
|
||||
if (!audioToggle.checked || !reply) return;
|
||||
|
||||
@@ -350,26 +351,45 @@ function speakInFrench(text) {
|
||||
window.speechSynthesis.cancel();
|
||||
const utterance = new SpeechSynthesisUtterance(text);
|
||||
utterance.lang = "fr-FR";
|
||||
utterance.rate = 0.98;
|
||||
utterance.pitch = 1;
|
||||
utterance.voice = pickFrenchVoice();
|
||||
utterance.rate = 0.9;
|
||||
utterance.pitch = 1.08;
|
||||
utterance.volume = 0.92;
|
||||
utterance.voice = pickSoftFrenchVoice();
|
||||
utterance.onend = resolve;
|
||||
utterance.onerror = resolve;
|
||||
window.speechSynthesis.speak(utterance);
|
||||
});
|
||||
}
|
||||
|
||||
function pickFrenchVoice() {
|
||||
function pickSoftFrenchVoice() {
|
||||
const voices = window.speechSynthesis.getVoices();
|
||||
const frenchVoices = voices.filter((voice) => voice.lang && voice.lang.toLowerCase().startsWith("fr"));
|
||||
const preferredNames = [
|
||||
"audrey",
|
||||
"aurelie",
|
||||
"aurélie",
|
||||
"marie",
|
||||
"julie",
|
||||
"celine",
|
||||
"céline",
|
||||
"lea",
|
||||
"léa",
|
||||
"amelie",
|
||||
"amélie",
|
||||
"sylvie",
|
||||
"hortense"
|
||||
];
|
||||
|
||||
return (
|
||||
voices.find((voice) => voice.lang === "fr-FR" && /google|microsoft/i.test(voice.name)) ||
|
||||
voices.find((voice) => voice.lang === "fr-FR") ||
|
||||
voices.find((voice) => voice.lang && voice.lang.toLowerCase().startsWith("fr")) ||
|
||||
frenchVoices.find((voice) => preferredNames.some((name) => voice.name.toLowerCase().includes(name))) ||
|
||||
frenchVoices.find((voice) => voice.lang === "fr-FR" && /female|femme|google|microsoft/i.test(voice.name)) ||
|
||||
frenchVoices.find((voice) => voice.lang === "fr-FR") ||
|
||||
frenchVoices[0] ||
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
window.speechSynthesis?.addEventListener?.("voiceschanged", pickFrenchVoice);
|
||||
window.speechSynthesis?.addEventListener?.("voiceschanged", pickSoftFrenchVoice);
|
||||
|
||||
async function resetConversation() {
|
||||
await fetch("/api/reset", {
|
||||
|
||||
Reference in New Issue
Block a user