comparison src/chat.js @ 31:1e7d855afde3

voices
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 Aug 2025 17:05:38 -0600
parents 505185272dd7
children d34d709a7a8e
comparison
equal deleted inserted replaced
30:d48f48e1b790 31:1e7d855afde3
1 'use strict'; 1 'use strict';
2 2
3 let chat; 3 let chat;
4 4
5 function setChat(newChat) { 5 function setChat(newChat) {
6 let audioChanged = chat && chat.voice != newChat.voice;
6 chat = newChat; 7 chat = newChat;
7 document.querySelector('[content] [name]').textContent = chat.name; 8 document.querySelector('[content] [name]').textContent = chat.name;
9 if(audioChanged) {
10 let s = `voice=${chat.voice}&`;
11 let audios = document.querySelectorAll('audio[src]');
12 for( let audio of audios ) {
13 audio.src = audio.src.replace(/voice=[^&]+&/,s);
14 }
15 }
8 } 16 }
9 17
10 function editChat(name) { 18 function editChat(name) {
11 let dialog = document.querySelector('dialog[edit]'); 19 let dialog = document.querySelector('dialog[edit]');
12 dialog.querySelector('input[name=name]').value = chat.name; 20 dialog.querySelector('input[name=name]').value = chat.name;
21 dialog.querySelector('select[name=voice]').value = chat.voice;
13 dialog.showModal(); 22 dialog.showModal();
14 } 23 }
15 24
16 function saveChat(form) { 25 function saveChat(form) {
17 closeModal(form); 26 closeModal(form);
48 audio.play(); 57 audio.play();
49 } 58 }
50 } 59 }
51 60
52 function handleChatMarkdown() { 61 function handleChatMarkdown() {
53 handleMarkdown(chat.language_region); 62 handleMarkdown(chat.language_region,chat.voice);
54 } 63 }
55 64
56 function scrollToEnd() { 65 function scrollToEnd() {
57 window.scrollTo(0, document.body.scrollHeight); 66 window.scrollTo(0, document.body.scrollHeight);
58 } 67 }
81 textarea.style.height = 'initial'; 90 textarea.style.height = 'initial';
82 textarea.style.height = (textarea.scrollHeight+2) + 'px'; 91 textarea.style.height = (textarea.scrollHeight+2) + 'px';
83 textarea.parentNode.scrollIntoViewIfNeeded(false); 92 textarea.parentNode.scrollIntoViewIfNeeded(false);
84 if( !audio ) 93 if( !audio )
85 audio = document.querySelector('div[buttons] audio'); 94 audio = document.querySelector('div[buttons] audio');
86 audio.src = `/tts.mp3?lang=${chat.language_region}&text=${encodeURIComponent(textarea.value)}`; 95 audio.src = `/tts.mp3?lang=${chat.language_region}&voice=${chat.voice}&text=${encodeURIComponent(textarea.value)}`;
87 } 96 }
88 97
89 function askAi() { 98 function askAi() {
90 let input = document.querySelector('textarea'); 99 let input = document.querySelector('textarea');
91 let url = `ai_ask.js?chat=${chat.id}&input=${encodeURIComponent(input.value)}`; 100 let url = `ai_ask.js?chat=${chat.id}&input=${encodeURIComponent(input.value)}`;