1

I would like to play some kind of text-to-speech with only numbers. I can record 10 wav files, but how can I combine them programmatically ?

For instance, the user types 1234, and the text-to-speech combines 1.wav with 2.wav, 3.wav and 4.wav to produce 1234.wav that plays "one two three four".

Thomas Joulin
  • 6,590
  • 9
  • 53
  • 88
  • Reading them from a dictionary? Anyway, you would not phisically "combine" them, you read them sequentially. – AsTheWormTurns Dec 02 '11 at 08:51
  • @AsTheWormTurns I read the text input (only digits), slit every digit so I no which digit files (1.wav, 2.wav...) I need to combine, and in which order – Thomas Joulin Dec 02 '11 at 09:09

3 Answers3

0

1) create a new destination sample buffer (you will want to know the sizes).

2) read the samples (e.g. using AudioFile and ExtAudioFile APIs) and write them in sequence to the buffer. You may want to add silence between the files.

It will help if your files are all the same bit depth (the destination bit depth - 16 should be fine) and sample rate.

Alternatively, if you have fixed, known, sample rates and bit depths for all files, you could just save them as raw sample data and be done in much less time because you could simply append the data as is without writing all the extra audio file reading programs.

justin
  • 104,054
  • 14
  • 179
  • 226
  • Can you detail a bit for an audio noob ? I guess I can control the rate and bit depth since I will record the original files manually. But I have no idea what those are. Can I juste set this values in Audacity ? – Thomas Joulin Dec 02 '11 at 08:58
  • 1
    Yes - using an editor (like Audacity) you can record and export the files at specific bit depths and sample rates. To change the bit depth, just reexport the file at 16 bit (for example). To change the sample rate, use Tracks->Resample. Or you can simply record them with these settings (which typically sounds better than applying sample rate conversion). If you want to export as raw audio, use Other->Export->Other->Options->RAW. – justin Dec 02 '11 at 09:14
  • @justin I LOVE you! Spent hours to figure how to export to raw in Audacity! – Avi Apr 13 '16 at 18:06
0

The open source project wavtools provides a good reference for this sort of work, if you're ok with perl. Otherwise there is a similar question with some java examples.

Community
  • 1
  • 1
FractalDoctor
  • 2,496
  • 23
  • 32
0

The simplist common .wav (RIFF) file format just has a 44 byte header in front of raw PCM samples. So, for these simple types of .wav files, you could just try reading the files as raw bytes, removing the 44 byte header from all but the first file, and concatening the samples. Or just play the concatenated samples directly using the Audio Queue API.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153