views:

68

answers:

2

How do i generate a gentle "beep" sound in python audiolab, without the use of external .wav files? I found the following example to generate random noise:

play(0.05 * np.random.randn(2, 48000))

Unfortunately i do not have enough knowledge of audio representations to create a beep (of a certain frequency) and i have no idea where to find some understandable documentation.

Any help on this would really be appreciated!

A: 

I figured it out:

play(0.05 * np.array([math.cos(x/40) for x in range(10000)]))

generates a pretty nice tone, in wich the values:

  • 0.05 defines the volume;
  • 40 the frequency;
  • 10000 the length of the tone.

Ciau!

Marlon
A: 

To be precise:

import audiolab
import scipy
x = scipy.cos((2*scipy.pi*f/fs)*scipy.arange(fs*T))
audiolab.play(x, fs)

where f is the frequency of the tone in Hertz, fs is the sampling rate, and T is the length of the tone in seconds.

Steve