Play sound


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Play sound
# 1  
Old 03-28-2013
Play sound

hi
i want to produce digit sounds.for ex: if my input text is four five six then code should able to
produce sounds corresponding to digits which are stored in some directory as four.wav,five.wav etc.Please help me
# 2  
Old 03-28-2013
(This could be homework.)

I am not sure i am understanding you correctly but I assume you want the sounds to be like morse code...

This will generate a single tone.

https://www.unix.com/shell-programmin...ator-demo.html

It is up to you to work out morse code with it which is not difficult...

Alternatively if it as voice you want the look at "cat" and use it to record raw voice data directly to disk, as <number>.raw using a laptop's internal mic for ease of use...

This assumes that you have /dev/dsp as a device.

Not sure why you need <number>.wav but if that is a requirement then look at SOX for doing all of the above...
This User Gave Thanks to wisecracker For This Post:
# 3  
Old 03-28-2013
Quote:
Originally Posted by wisecracker
(This could be homework.)

I am not sure i am understanding you correctly but I assume you want the sounds to be like morse code...

This will generate a single tone.

https://www.unix.com/shell-programmin...ator-demo.html

It is up to you to work out morse code with it which is not difficult...

Alternatively if it as voice you want the look at "cat" and use it to record raw voice data directly to disk, as <number>.raw using a laptop's internal mic for ease of use...

This assumes that you have /dev/dsp as a device.

Not sure why you need <number>.wav but if that is a requirement then look at SOX for doing all of the above...
I need a simple text to speech converter.I have already have sounds corresponding to digits(0 to 9) in wav format.So when my input is for eg: one two three,then i should able to play one.wav two,wav three.wav.I hope you understood my problem
# 4  
Old 03-28-2013
I suppose a brutally simple way would just be a loop:

Code:
tr '[A-Z]' '[a-z]' < inputfile | while read LINE
do
        STR=""
        set -- $LINE
        while [ "$#" -gt 0 ]
        do
                [ -f "wavdir/$1.wav" ] && STR="$STR wavdir/$1.wav"
                shift
        done

        [ ! -z "$STR" ] && play $STR
done

It converts all uppercase into lowercase, then reads every line, splits words on whitespace into $1 $2 ..., loops over $1...$N, and for every word matching a file inside wavdir/, adds it to a list of files to be played then plays it.

You need sox's play command for this...
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 03-28-2013
Hi sreejithalokkan...

Makes much more sense now... ;o)

I will assume that you will need a a dedicated shell Audio I/O app for platform independence.
So I will suggest SOX...

I have to assume also that this is some _homework_ style project, but not necessarily so.

OK.

Think of your problem...

Keep it simple...

I am not going to give you the code directly as you learn nothing about what is going on...

Code:
1) Generate a function, let us call it "say_it()"
2) inside the function call SOX somehow to play your *.wav file. Something like this:-

say_it()
{
        /full/absolute/path/to/sox <your player options> somefile.wav
}

3) Use if - then - fi to call it something like this:-

number="one"
if [ "$number" == "one" ]
then
        # Your new function...
        say_it
fi

All "case"s can be catered for this way and this is its simplest and easiest to understand form, albeit slow...

Next try and make the function universal by making "somefile.wav" a variable...

This User Gave Thanks to wisecracker For This Post:
# 6  
Old 03-28-2013
Quite the same solution as Corona688; uses aplay to play wav files:
Code:
#!/bin/sh

while read line; do
	set -- $line
	while [ "$1" ]; do
		echo aplay "$1.wav" # remove echo to actually let aplay play the wav file
		shift
	done
done

exit 0

Example usage: ~/unix.com$ echo input_file | sh the_above_script.sh

Code:
~/unix.com$ cat input_file
one four five
two
three

~/unix.com$ cat input_file | sh the_above_script.sh 
aplay one.wav
aplay four.wav
aplay five.wav
aplay two.wav
aplay three.wav

Of course, remove the echo that prevent the aplay to do its job Smilie
# 7  
Old 03-28-2013
Code:
while [ "$1" ]

I don't think this does quite what you think it does. To check if a string is empty:

Code:
while [ ! -z "$1" ]

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making a play-list

approximately the same question as the last time, but unfortunately I didn't get a working answer. I made a script with bash and gtkdialog that create a play-list. The output is for example : gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 28897 |... (3 Replies)
Discussion started by: jkfloris
3 Replies

2. Slackware

Can't play sound files with aplay or cat to /dev/dsp

I am having problems using soundes. Until a few moments ago the following commands produced errors and no sound: cat /usr/share/apps/kolf/sounds/blackhole.wav/ > /dev/dsp yielded: /dev/dsp: Invalid argument cat /usr/share/apps/kolf/sounds/blackhole.wav > /dev/audio yelded: /dev/audio:... (3 Replies)
Discussion started by: slak0
3 Replies

3. Linux

Can not play sound in Linux RHEL5.

Hi All, Recently I installed Linux RHEL5 on my machine. It seems that I can not play sound on RHEL5. I have real player installed along with RHEL5 but, when I try to play any song, the error message comes up saying "Can not open the audio device.Another application may be using it." Does any... (2 Replies)
Discussion started by: gydave
2 Replies

4. Linux

how can i play the gam

can some1 tell me how to start playing? (2 Replies)
Discussion started by: 123456
2 Replies

5. UNIX for Advanced & Expert Users

play

dear friends, i have linux system . can i play songs in linux system. like winamp player in windows. let me know. (2 Replies)
Discussion started by: rajan_ka1
2 Replies

6. UNIX for Dummies Questions & Answers

How Can I Play A Cd On Unix

HI I AM A FRESH NEW USER ...I MEAN I JUST GOT A COMPUTER ALMOST FOR FREE AND IT RUNS UNIX WHICH I DIDN'T EXPECT AND DONT KNOW HOW TO WORK ON IT I THOUGHT IT'LL BE WITH WINDOWS ..YOU KNOW SO HOW DO I PLAY A CD IN IT. REMEMBER I KNOW NOTHING ABOUT UNIX , BUT I THINK I'LL GET OVER IT... (1 Reply)
Discussion started by: IMOTEB
1 Replies

7. UNIX for Advanced & Expert Users

Need something new to play with

I posted this question in the dummies forums, but I would like to get a more expert opinion... I am looking for a new OS to play with. I have a celron 450 running slackware linux, a powermac G4 450 running Mac OS X (Which by the way has 81 days of uptime as of this moment), a PowerBook G3 running... (5 Replies)
Discussion started by: dewhite04
5 Replies

8. UNIX for Dummies Questions & Answers

play cd? how?

hi all, How do I set up my cdrom to play some regular audio cd (not cd-r or cd-rw). I know that my cdrom has been mounted as it does pop up the file manager if I put in, e.g., the office52 cd. Thanks in advance. Andre (3 Replies)
Discussion started by: andrec
3 Replies
Login or Register to Ask a Question