initial commit
This commit is contained in:
55
web/server.js
Normal file
55
web/server.js
Normal file
@ -0,0 +1,55 @@
|
||||
const WebSocket = require('ws');
|
||||
const wss = new WebSocket.Server({ port: 8081 });
|
||||
console.log('WebSocket server started on port 8081');
|
||||
|
||||
//we use https://hub.docker.com/r/onerahmet/openai-whisper-asr-webservice to transcribe the audio
|
||||
//docker run -p 9009:9009 -d onerahmet/openai-whisper-asr-webservice
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
console.log('Client ' + ws._socket.remoteAddress + ' connected');
|
||||
ws.on('message', (data) => {
|
||||
console.log('Received data from client: ' + data.length + ' bytes');
|
||||
var request = require('request');
|
||||
var formData = {
|
||||
task: 'transcribe',
|
||||
language: 'en-US',
|
||||
output: 'json',
|
||||
audio_file: {
|
||||
value: data,
|
||||
options: {
|
||||
filename: 'audio.ogg',
|
||||
contentType: 'audio/ogg'
|
||||
}
|
||||
}
|
||||
};
|
||||
request.post({url:'http://192.168.0.10:9009/asr', formData: formData}, function optionalCallback(err, httpResponse, body) {
|
||||
if (err) {
|
||||
return console.error('upload failed:', err);
|
||||
}
|
||||
console.log('Upload successful! Server responded with:', body);
|
||||
ws.send(">>: " + body);
|
||||
});
|
||||
|
||||
ws.send("Processing audio...");
|
||||
});
|
||||
});
|
||||
|
||||
function transcribeAudio(audioData) {
|
||||
// Use a speech-to-text library to transcribe the audio data
|
||||
//return transcription;
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
|
||||
// --- web server that servers client.html
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const path = require('path');
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'client.html'));
|
||||
});
|
||||
|
||||
app.listen(8080, () => {
|
||||
console.log('Server listening on port 8080');
|
||||
});
|
Reference in New Issue
Block a user