dotenv if exists;

auto create rec folder;
select audio device on client;
This commit is contained in:
Dobromir Popov
2023-03-07 11:41:50 +02:00
parent 2f56d76042
commit 6429852505
2 changed files with 75 additions and 14 deletions

View File

@ -4,8 +4,10 @@ console.log('WebSocket server started on port 8081');
//load TTS_BACHEND_URL from .env file
//require('dotenv').config();
//load .env file
if (require('dotenv')) {
require('dotenv').config()
}
console.log(process.env)
console.log(process.env.TTS_BACKEND_URL)
@ -32,13 +34,17 @@ wss.on('connection', (ws) => {
}
}
};
//save the audio data to a file to /rec folder
var fs = require('fs');
var timestampfilename = Date.now();
fs.writeFile('./rec/audio' + timestampfilename + '.ogg', data, function (err) {
//fs.writeFile('audio' + timestampfilename + '.ogg', data, function (err) {
var timestampfilename = Date.now("yyyymmdd-hhMMss");
//save the audio data to a file to /rec subfolder
var fs = require('fs');
fs.mkdir('rec', { recursive: true }, (err) => {
if (err) throw err;
});
fs.writeFile('rec/audio' + timestampfilename + '.ogg', data, function (err) {
if (err) {
return console.log(err);
}
@ -47,7 +53,7 @@ wss.on('connection', (ws) => {
request.post({url:'http://192.168.0.10:9008/asr', formData: formData}, function optionalCallback(err, httpResponse, body) {
request.post({ url: process.env.TTS_BACKEND_URL, formData: formData }, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
@ -76,7 +82,7 @@ app.get('/', (req, res) => {
//get WS url from .env file
app.get('/wsurl', (req, res) => {
res.send(process.env.WS_URL, 200, {'Content-Type': 'text/plain'});
res.send(process.env.WS_URL, 200, { 'Content-Type': 'text/plain' });
});