Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have done this:

me@riverbrain:~/sgf$ echo "test" | text2wave -otype raw -F 16000 >> test.raw

which produced a headerless audio file. The wonderful thing about this file is that it can be concatenated (using cat, like text) with another raw audio file.

Of course, I've got a problem. The problem is that I can't play it yet.

me@riverbrain:~/sgf$ play test.raw 

play FAIL formats: bad input format for file `test.raw': sampling rate was not specified

and also, when specifying sample rate

me@riverbrain:~/sgf$ play -r 16000 test.raw 
play FAIL formats: bad input format for file `test.raw': data encoding was not specified

When I looked up some information 'encoding' I got the feeling that it had a lot to do with your processor architecture, but maybe I'm wrong. Anyway, I can't find any documentation about how to 'ask' the computer what the data encoding of the raw audio file is. And I also I know what the sample rate is, due to setting it myself, but that's as far as I'm able to get.

share|improve this question
2  
There is no standard raw format. You need to find out what parameters the application that produced it used. Unfortunately, that's not always well-documented. –  Gilles Dec 1 '11 at 23:29

3 Answers 3

up vote 4 down vote accepted

It can vary—but at least for me, text2wave produces 1-channel, 16-bit, signed integer PCM. These are fairly normal—and it'll be very clear when you have them right (e.g., if you unsigned-integer by mistake, you'd get extremely distorted sound)

With play, that looks like:

play -r 16000 -b 16 -c 1 -e signed-integer /tmp/foo.raw
play -r 16000 -2 -s -c 1 /tmp/foo.raw # obsolete way for older versions of Sox

These parameters are configured in Festival somewhere, I suspect. Some of them may be hardcoded as well.

The only architecture-dependent thing you may encounter is big vs. little endian; on my little-endian machine Festival is writing little-endian; if I moved that file to a big-endian machine I'd likely need to add -L. If text2wav were run on a big-endian machine, I'm not sure if it'd write big- or little- endian data.

share|improve this answer
    
thank you. all of these responses were great, but this is the solution i ended up using. –  ixtmixilix Dec 6 '11 at 19:22

You can probably create your own RIFF header. A bit of bashing should do it.. and just cat the header to your other piece(s)...

This link shows the header layout: The Canonical WAVE file format

There is also a related link on SO: Converting RAW audio data to WAV with scripting, but the mplayer/mencoder answers have a zero marked-up count. However, it sems that SoX works.

SoX gets a mention in both the above links, and is available in Ubuntu's repo; I suppose it is in others also.

PS... I just tried using play (didn't know it existed) and discovered it is SoX! ...The SO link gives an example, copied here: sox -r 44100 -e unsigned -b 8 -c 1 <RAW_FILE> <TARGET_FILE>

If you can't get it working with sox, maybe mplayer/mencoder or the RIFF header will get it going for you.

share|improve this answer

Use aplay instead of play to play a raw file, this way you can specify that it's a raw audio by the -t switch:

aplay -q -c 2 -t raw -f s16 test.raw
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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