pythonaudionumpy

beep sound in python audiolab


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!


Solution

  • 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.