Search code examples
rubytext-to-speechalsa

How can I run ruby-espeak as root user?


I am creating a ruby based application and I wish it to speak some text. So far am using espeak:

fork{exec ("espeak 'New file located #{timelog.hour} #{timelog.min}' \" > /dev/null")}

which works when i run it as normal user, but I need this script to run as root. When it runs as root I get:

ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

Why can't I run this script as root? Also, is there another way to make my ruby script do TTS (Text To Speech)?

Added: I have even tried Festival when i run it nothing happens even as normal user.

require "rubygems"
require "festivaltts4r"
"I'm talking".to_speech

(gem list) ruby 1.9

bigdecimal (1.1.0)
clickatell (0.8.2)
espeak-ruby (0.4.0)
festivaltts4r (0.2.0)
ffi (1.1.5)
hoe (3.1.0)
io-console (0.3)
json (1.5.4)
minitest (2.5.1)
nice-ffi (0.4)
rake (0.9.2.2)
rdoc (3.9.4)
ruby-sdl-ffi (0.4)
rubygame (2.6.4)
sms_fu (1.1.2)
tts (0.3.0)

OS:OpenSuse


Solution

  • Found Solution Run su Instead of sudo and it works ("espeak") that is Thanks for all u'r help StackoverFlow Community ;>