lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Your link seems to be very intersting, but at this moment, perhaps, more complicated for my humble purpose. If I understood, I had to study the wave format and manage some structures in C. Actually, I have never dealt with wave formats and programmed anything in C.

Let me explain what I really want. Espeak is a very good multiplatform tool that converts text to speech. So with the code bellow, I can create a wave file from a text file:

module('tts', package.seeall)

wave =
{
language = 'pt',
quality = 48,
amplitude = 140,
pitch = 50,
speed = 260,
splittime = 15
}

function wave.create(profile)
local command
setmetatable(profile, {__index = wave})
if profile.filename then
command = string.format("espeak -f '%s' -w '%s' -v '%s' -a %d -p %d -s %d --split=%d", profile.filename, profile.filename .. '.wav', profile.language, profile.amplitude, profile.pitch, profile.speed, profile.splittime)
else
command = string.format("espeak '%s' -w '%s' -v '%s' -a %d -p %d -s %d --split=%d", profile.text, 'temp.wav', profile.language,
profile.amplitude, profile.pitch, profile.speed, profile.splittime)
end
return os.execute(command)
end

wave.create{filename = 'test'}

This will produce the following files:

test_01.wav
test_02.wav
test_03.wav

I am blind. After creating the wav files, I can convert it to mp3 and, having saved it in a pendrive, I am able to read books everywhere with a mp3 player.

So, the objective of my application is two improve my Lua skills and to provide a best way to use espeak.

And why have I asked you about wave files? Doesn'te above code work? Yes, it does. But if the book has 30 or 40 tracks, it's not easy to manage it in the mp3 player because tracks doesn't receive a name.

What do I want to do? With the shown code, we have created: text_01.wav, test_02.wav, test_03.wav... Suppose the book Around the world in 80 days. Before the content of each track, I want to listen: "Around the world in 80 days 1", "rround the world in 80 days ... When the device plays the track, the name of it is shown in a display. But I am blind! The name should be spoken not shown.

For each track of the book, I will create a temp wave with the name and the number of the track and to join the temp wave with the respective track. The two files will be created by my application, so I can assure the sample rate and the other parameters are compatible. I don't need to verify the possibility of concatenation. In my case, concatenation is always possible.

I know to create the wave files, but I am not able to join them. I have never read binary files in Lua and I don't know how to do it. I can learn, undoubtedly, but I don't know exactly from where to start. For this purpose, if there is a easiest way to implement, perhaps it would be better.

Em 04-09-2011 10:55, Peng Zhicheng escreveu:
于 2011-9-4 21:35, Luciano de Souza 写道:
Hi listers,

Is there a way to join to wave files into a single one? I prefered to do it in Lua in order to keep the code multiplatform, but if it's not possible, how to do it in Linux?

wave.join('file1.wav', 'file2.wav', file3.wav)

The desirable result is that file3.wav is the concatenation of file1 and file2, being file1 the first and file2 the last sound.

Luciano


you may have to parse the file header to make sure the two source files are with same sample rate, bit rate, sample precision (a.k.a. bits per sample), and number of channels, and parameters like such.

if they are the same, then you just create an new file, keep the parameters same with the input files, but set the data size to the sum of the input source files, and concat the payload data bytes, put them in chunks.

if they are not the same, you can't concat them directly. you must convert either souce file to be same with the other, then do
the concat.

you may google for the `.wav' file header format, it is quite simple.