File size: 846 Bytes
e2d284e
 
 
 
 
 
c6b6d05
e2d284e
 
c6b6d05
e2d284e
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
document.getElementById('submit-audio').addEventListener('click', async () => {
    const audioInput = document.getElementById('audio-input');
    if (audioInput.files.length === 0) {
        alert('Please select an audio file.');
        return;
    }

    const formData = new FormData();
    formData.append('audio', audioInput.files[0]);

    try {
        const response = await fetch('/process_audio', {
            method: 'POST',
            body: formData
        });
        const data = await response.json();
        document.querySelector('.response-text').textContent = data.response_text;
        const audioElement = document.querySelector('.response-audio');
        audioElement.src = data.response_audio_url;
        audioElement.style.display = 'block';
    } catch (error) {
        console.error('Error:', error);
    }
});