Text-To-Speech in Node js

I already have my pre-trained model and its working fine. When I say something, it outputs the text. Now, I want to do the text-to-speech, for example when I say “I am not fine”, a wav file shall be outputted saying “what happened?”

I tried to do it using the package “node-wav-player” in the app.js and its being compiled successfully but the wav file is not outputted when I say something.


Code in app.js:

renderRecognitionOutput() {
	return (<ul>
		{this.state.recognitionOutput.map((r) => {
			if (r.text === "I am not fine"){
			   const player = require('node-wav-player');
               player.play({
                path: 'M2File5.wav',
                }).then(() => {
                    console.log('The wav file started to be played successfully.');
                }).catch((error) => {
                    console.error(error);
                });
			}
			else {
			   const player = require('node-wav-player');
               player.play({
                path: 'M2File7.wav',
                }).then(() => {
                    console.log('The wav file started to be played successfully.');
                }).catch((error) => {
                    console.error(error);
                });
			}
			return (<li key={r.id}>{r.text}</li>);
		})}
	</ul>)
}

Please help :slight_smile:

Also, I am using Deepspeech version deepspeech 0.9.3 and the deepspeech example web microphone websocket.

Hi
your problem is honestly not related to a DeepSpeech text-to-speech problem (as the title would suggest). It’s instead about how to play a WAV file!

You mention, probably this DeepSpeech demo code, using the expternal speaker package to play an audio WAV file. So I guess yo need any NodeJs package as speaker, node-wav-player, or anything else able to play a WAV on your target operating system.

A quick and dirty solution is to spawn, from your NodeJs program, a bash command (external process) that play the file (in background, without blocking your NodeJs program). By example, the most standard way to play a WAV file in Linux is using the aplay command, which is part of the ALSA system:

const { exec } = require('child_process')
const wavFile = 'M2File5.wav'

exec(`aplay -q ${wavFile}`)