This commit is contained in:
YannAhlgrim
2025-10-08 15:23:23 +02:00
parent b59f52cf86
commit 5e6eae61cc
8 changed files with 288 additions and 70 deletions
+28 -16
View File
@@ -31,23 +31,35 @@ export default function Home() {
}
async function sendAudio(blob) {
const form = new FormData()
// Convert webm to wav on the client is complex; many servers accept webm/ogg.
form.append('file', blob, 'recording.webm')
try {
const form = new FormData()
// Convert webm to wav on the client is complex; many servers accept webm/ogg.
form.append('file', blob, 'recording.webm')
const res = await fetch('http://localhost:8000/chat', { method: 'POST', body: form })
if (!res.ok) {
const text = await res.text()
alert('Error: ' + res.status + ' ' + text)
return
}
const audioBlob = await res.blob()
const url = URL.createObjectURL(audioBlob)
if (audioRef.current) {
audioRef.current.src = url
audioRef.current.play()
setPlaying(true)
audioRef.current.onended = () => setPlaying(false)
console.log('Sending request to backend...')
const res = await fetch('http://localhost:8000/chat', { method: 'POST', body: form })
console.log('Response received:', res.status, res.statusText)
if (!res.ok) {
const text = await res.text()
alert('Error: ' + res.status + ' ' + text)
return
}
console.log('Converting response to blob...')
const audioBlob = await res.blob()
console.log('Audio blob created, size:', audioBlob.size)
const url = URL.createObjectURL(audioBlob)
if (audioRef.current) {
audioRef.current.src = url
audioRef.current.play()
setPlaying(true)
audioRef.current.onended = () => setPlaying(false)
}
} catch (error) {
console.error('Error in sendAudio:', error)
alert('Failed to process audio: ' + error.message)
}
}