20 lines
608 B
JavaScript
20 lines
608 B
JavaScript
// Inicializar la grabación
|
|
var wavesurfer = WaveSurfer.create({
|
|
container: '#waveform'
|
|
});
|
|
wavesurfer.microphone.start();
|
|
|
|
// Obtener los datos de audio en binario y enviarlos al servidor
|
|
var audioData = wavesurfer.microphone.getAudioData();
|
|
var binaryAudioData = new Float32Array(audioData);
|
|
var buffer = new ArrayBuffer(binaryAudioData.length * 4);
|
|
var view = new Float32Array(buffer);
|
|
for (var i = 0; i < binaryAudioData.length; i++) {
|
|
view[i] = binaryAudioData[i];
|
|
}
|
|
|
|
var ws = new WebSocket('ws://localhost:8000');
|
|
ws.binaryType = 'arraybuffer';
|
|
ws.onopen = function() {
|
|
ws.send(buffer);
|
|
}; |