1

I am trying to get a Raspberry Pi to work without a screen. However I want Text To Speech functions. I have installed festival and gotten the USB sound device to be default. Everything works except when the NodeJS script is run with sudo, or if it is run at startup (which I imagine would be with sudo as well) the audio never plays.

var say = require('say');
var express = require('express');
var app = express();

var sys = require('sys');
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }

function speak(text) {
   say.speak(text, 'Alex', 0.8); 
   //exec("echo " + text + " | festival --tts", puts); //another attempt
}

app.get('/say', function(request, response) {
    speak(request.query.text);
    response.send({"state":"I have spoken: " + request.query.text});
});

I have put this into a file called "server.js" and the way I get this to run at boot is to modify the /etc/rc.local file to include

node /path/to/server.js

But when it is run in this manner, or with sudo, the Text To Speech library does not work.

NodeJS Version: 0.10.29

1

This is just a guess but is your RPi set to run a CLI or a GUI when you login? Quite often distributions are set to give the sound hardware over to a user that logs into a GUI and does not even configure the hardware until that happens - and then it locks the hardware to THAT user so that not even root can access it until that user logs out - there are valid reasons for doing so as you do not want a second (possibly remote) user gaining control of say the microphone to listen in on you as the first user.

You will have to change some settings in order to allow the use of the audio hardware by a background daemon. This is particular the case with pulseaudio which (coming from the same stable as systemd and network mangler) makes assumptions about what a user wants and can make it less clear how to do things different to how they expect you to use the software, IMHO! For that you have to configure it to run in "server" mode - which places some extra constraints on the setup (it is not permitted to load modules "on-demand." Instead they must, for security, be explicitly listed to be loaded - also I do not think you can run the PA threads in Real-time mode IIRC.)

To give a fuller answer I think we will want to know more about the audio system and software that is in use. Presumable it is the HDMI audio/ RCA Phono(older RPIs) / 3.5mm Jack (newer RPis), but what distribution are you using?

  • Awesome! You definitely put me on the right track! I got it working by running the script in the /etc/profile rather than /etc/rc.local -> because I want it run by that specific user. Just a tip to anyone doing this: put a " &" after the script otherwise you lock the UI. I am running Raspbian (noobs) and don't really want to lose the option of a GUI just yet. – Quintin Balsdon May 8 '16 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.