Mercurial Hosting > lang
comparison src/chat.js @ 14:47b00cce8b53
stt
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Jul 2025 00:12:05 -0600 |
parents | 65bd7e245c63 |
children | 3a80ddafe5a4 |
comparison
equal
deleted
inserted
replaced
13:65bd7e245c63 | 14:47b00cce8b53 |
---|---|
69 } | 69 } |
70 | 70 |
71 function fixTextarea(textarea) { | 71 function fixTextarea(textarea) { |
72 textarea.style.height = 'initial'; | 72 textarea.style.height = 'initial'; |
73 textarea.style.height = (textarea.scrollHeight+2) + 'px'; | 73 textarea.style.height = (textarea.scrollHeight+2) + 'px'; |
74 textarea.scrollIntoViewIfNeeded(false); | 74 textarea.parentNode.scrollIntoViewIfNeeded(false); |
75 } | 75 } |
76 | 76 |
77 function askAi() { | 77 function askAi() { |
78 let input = document.querySelector('textarea'); | 78 let input = document.querySelector('textarea'); |
79 let url = `ai_ask.js?chat=${chatId}&input=${encodeURIComponent(input.value)}`; | 79 let url = `ai_ask.js?chat=${chatId}&input=${encodeURIComponent(input.value)}`; |
80 ajax(url); | 80 ajax(url); |
81 input.value = ''; | 81 input.value = ''; |
82 fixTextarea(input); | 82 fixTextarea(input); |
83 showWaitingAiIcon(); | 83 showWaitingAiIcon(); |
84 } | 84 } |
85 | |
86 | |
87 function setText(text) { | |
88 let textarea = document.querySelector('textarea'); | |
89 textarea.value = text; | |
90 fixTextarea(textarea); | |
91 } | |
92 | |
93 let recorder = null; | |
94 let chunks; | |
95 | |
96 function startRecording() { | |
97 chunks = []; | |
98 function record(stream) { | |
99 recorder = new MediaRecorder( stream, { mimeType: 'audio/webm;codecs=opus' } ); | |
100 recorder.ondataavailable = function(event) { | |
101 chunks.push(event.data); | |
102 }; | |
103 recorder.onstop = function(event) { | |
104 recorder = null; | |
105 let blob = new Blob(chunks, { type: 'audio/webm' }); | |
106 let formData = new FormData(); | |
107 formData.append('audio', blob, 'recording.webm'); | |
108 ajax('stt.js',formData); | |
109 document.querySelector('button[record]').textContent = 'Record'; | |
110 }; | |
111 recorder.start(); | |
112 } | |
113 navigator.mediaDevices.getUserMedia({ audio: { channelCount: 1 } }).then(record); | |
114 document.querySelector('button[record]').textContent = 'Stop Recording'; | |
115 } | |
116 | |
117 function toggleRecording() { | |
118 if( recorder === null ) { | |
119 startRecording(); | |
120 } else { | |
121 recorder.stop(); | |
122 } | |
123 } |