[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Sine Waves



A speech synthesizer like you describe would be a hard project, which would require you to learn Digital Signal Processing techniques, or at least find DSP algorithms that you can implement with Numeric.  I think that in DSP the purpose of the Fast Fourier Transform is to analyze/manipulate data in the frequency domain.  I would read tutorials on FFT, or find an intro book on DSP like Understanding Digital Signal Processing by Lyons (haven't read it yet, but it's on my list to get/read).  Numeric has some built-ins for FFT.

If you want to build a synth, it might be interesting first to check out graphical programming environments for audio such as the MAX/MSP demo, Miller Puckette's free software Pure Data, or the VST editor SynthEdit.  One of those things with lots of little boxes and patch cords. :)  Using PD you could probably take a working model and then figure out how to translate it into the kind of Python implementation you want. 


On 12/11/05, Kris Schnee <kschnee@xxxxxxxxxx> wrote:
David Tweet wrote:
> I would also suggest looking at more of the Numeric built-ins, such as
> "fromfunction".
>    For example, instead of looping to construct a native python list and
> then converting to an array, you can do:
>
> arr_float = fromfunction(lambda x,
> y:(sin(x*freq*(6.28318/sample_rate)*length)*volume),
>                  (sample_rate * length, 2))
>
> arr_int = arr_float.astype(Int16)
> return arr_int
>
>     This converts using sndarray just fine, although not if you are
> using NumArray for some reason, you have to be using Numeric.  The "sin"
> function here is from importing Numeric.  The type conversion is because
> something complained about using the "int" type coercion inside the lambda.

Thanks. I got the sine wave maker working by limiting the volume (yeah,
it must've been chopping off the upper parts of the sine waves) and
eliminating the "*length" part, which didn't belong there. Looks like I
could construct a standard Western musical scale by setting standard
note A4 to 440 Hz, and calculating each higher note as 1.05946 times the
previous note's frequency.
(<http://www.physlink.com/Education/AskExperts/ae165.cfm >)

The reason I started messing with sound generation was an experiment
with speech synthesis -- I had thought the array data was _frequency_
instead of volume. That explains why my attempt to do a modern
speech-synth trick didn't work:

Apparently good speech synth systems don't just string together English
phonemes. They alter the pitch of the head and tail of each, so that
there's a smooth variation in frequency from one to the next, imitating
the continuous stream of sound produced by a human speaking even
multiple words. I thought I was being clever by writing a function to
tweak the array data to make the values there closer together at the
head/tail of phoneme pairs, but noticed no effect.

It looks like since the array values represent volume (pressure,
really), I'd have to calculate what the frequency is on either end and
do some sort of Numeric function to compress/stretch the data, maybe
even changing the resulting array's length. This sounds hard; any leads?

Kris




--
David Tweet
__________________
http://davidtweet.com