Text-To-Speach für Linux hinzugefügt

This commit is contained in:
Robert Richter 2019-04-04 13:45:55 +02:00
parent 44096c32cc
commit bfed361bec

View File

@ -83,7 +83,7 @@ module.exports = function(io, sql, async, app_cfg) {
einsatzdaten.besonderheiten = ''; einsatzdaten.besonderheiten = '';
einsatzdaten.strasse = ''; einsatzdaten.strasse = '';
einsatzdaten.wgs84_x = einsatzdaten.wgs84_x.substring(0, einsatzdaten.wgs84_x.indexOf('.') + 3); einsatzdaten.wgs84_x = einsatzdaten.wgs84_x.substring(0, einsatzdaten.wgs84_x.indexOf('.') + 3);
einsatzdaten.wgs84_y = einsatzdaten.wgs84_y.substring(0, einsatzdaten.wgs84_y.indexOf('.') + 3); einsatzdaten.wgs84_y = einsatzdaten.wgs84_y.substring(0, einsatzdaten.wgs84_y.indexOf('.') + 3);
}; };
// Einsatz senden // Einsatz senden
io.sockets.to(socket_id).emit('io.neuerEinsatz', einsatzdaten) io.sockets.to(socket_id).emit('io.neuerEinsatz', einsatzdaten)
@ -139,41 +139,73 @@ module.exports = function(io, sql, async, app_cfg) {
// Abschluss // Abschluss
tts_text = tts_text + '. Ende der Durchsage!'; tts_text = tts_text + '. Ende der Durchsage!';
// Sprachansage als mp3 erstellen // Sprachansage als mp3 erstellen
if (process.platform === "win32") { switch (process.platform) {
// Powershell //if (process.platform === "win32") {
var proc = require('child_process'); case 'win32':
var commands = [ // Powershell
// TTS-Schnittstelle von Windows var proc = require('child_process');
'Add-Type -AssemblyName System.speech;' + var commands = [
'$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;' + // TTS-Schnittstelle von Windows
// Ausgabedatei und Sprachtext 'Add-Type -AssemblyName System.speech;' +
'$speak.SetOutputToWaveFile(\"' + wav_tts + '\");' + '$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;' +
'$speak.Speak(\"' + tts_text + '\");' + // Ausgabedatei und Sprachtext
'$speak.Dispose();' + '$speak.SetOutputToWaveFile(\"' + wav_tts + '\");' +
// speak.wav in mp3 umwandeln '$speak.Speak(\"' + tts_text + '\");' +
'ffmpeg -nostats -hide_banner -loglevel 0 -y -i ' + wav_tts + ' -vn -ar 44100 -ac 2 -ab 128k -f mp3 ' + mp3_tmp + ';' + '$speak.Dispose();' +
// Gong und Ansage zu einer mp3 zusammensetzen // speak.wav in mp3 umwandeln
'ffmpeg -nostats -hide_banner -loglevel 0 -y -i \"concat:' + mp3_bell + '|' + mp3_tmp + '\" -acodec copy ' + mp3_tts + ';' + 'ffmpeg -nostats -hide_banner -loglevel 0 -y -i ' + wav_tts + ' -vn -ar 44100 -ac 2 -ab 128k -f mp3 ' + mp3_tmp + ';' +
'rm ' + wav_tts + ';' + // Gong und Ansage zu einer mp3 zusammensetzen
'rm ' + mp3_tmp + ';' 'ffmpeg -nostats -hide_banner -loglevel 0 -y -i \"concat:' + mp3_bell + '|' + mp3_tmp + '\" -acodec copy ' + mp3_tts + ';' +
]; 'rm ' + wav_tts + ';' +
var options = { 'rm ' + mp3_tmp + ';'
shell: true ];
}; var options = {
var childD = proc.spawn('powershell', commands); shell: true
childD.stdin.setEncoding('ascii'); };
childD.stderr.setEncoding('ascii'); var childD = proc.spawn('powershell', commands);
childD.stderr.on('data', function(data) { childD.stdin.setEncoding('ascii');
sql.db_log('Fehler-TTS', data); childD.stderr.setEncoding('ascii');
childD.stderr.on('data', function(data) {
sql.db_log('Fehler-TTS', data);
callback && callback(null);
});
childD.on('exit', function() {
callback && callback(mp3_url);
});
childD.stdin.end();
break;
case 'linux':
// bash
var proc = require('child_process');
var commands = [
// TTS-Schnittstelle SVOX PicoTTS
'-c', `
pico2wave --lang=de-DE --wave=` + wav_tts + ` \"` + tts_text + `\"
ffmpeg -nostats -hide_banner -loglevel 0 -y -i ` + wav_tts + ` -vn -ar 44100 -ac 2 -ab 128k -f mp3 ` + mp3_tmp + `
ffmpeg -nostats -hide_banner -loglevel 0 -y -i \"concat:` + mp3_bell + `|` + mp3_tmp + `\" -acodec copy ` + mp3_tts + `
rm ` + wav_tts + `
rm ` + mp3_tmp
];
var options = {
shell: true
};
console.log(commands);
var childD = proc.spawn('/bin/sh', commands);
childD.stdin.setEncoding('ascii');
childD.stderr.setEncoding('ascii');
childD.stderr.on('data', function(data) {
sql.db_log('Fehler-TTS', data);
callback && callback(null);
});
childD.on('exit', function() {
callback && callback(mp3_url);
});
childD.stdin.end();
break;
// } else {
default:
sql.db_log('Fehler-TTS', 'TTS für dieses Server-Betriebssystem nicht verfügbar');
callback && callback(null); callback && callback(null);
});
childD.on('exit', function() {
callback && callback(mp3_url);
});
childD.stdin.end();
} else {
sql.db_log('Fehler-TTS', 'OS ist nicht Windows');
callback && callback(null);
}; };
}); });
}; };