Tutorial¶
Make simple sound¶
This example is make 440 Hz sine wave sound.
>>> import gensound
>>> sound = gensound.Sound.from_sinwave(440)
The Sound class has some class methods for generating simple tones.
Please see reference.
Play and save¶
Play made sound with play method, like this.
>>> sound.play()
Or, can write into disk with write method.
>>> sound.write('out.wav')
Overlay or concatenate¶
Make two sounds,
>>> a = gensound.Sound.from_sinwave(440)
>>> b = gensound.Sound.from_sinwave(880)
and overlay they with overlay function.
>>> overlay = gensound.overlay(a, b)
The overlay is the same duration as a and b, and play both of 440 Hz and 880 Hz.
Or, concatenate they with concat function.
>>> concat = gensound.concat(a, b)
The concat is playing a then b.
Use sound effects¶
PyGenSound has some effects like fade-in, fade-out, high pass or low pass filter.
In PyGenSound, resampling and changing speed is classified as an effect.
This sample will apply fade-out effect to sound a.
>>> effect = gensound.LinearFadeOut()
>>> a_fadeout = effect.apply(a)
You can use effects as a like a stream operator of C++.
>>> a_fade = a >> gensound.LinearFadeOut() >> gensound.LinearFadeIn()
>>> a_fade == gensound.LinearFadeIn() << gensound.LinearFadeOut() << a
True
Please see detail about effects to reference
Examples¶
Make NHK time signal sound¶
import gensound
wait = gensound.Sound.silence(duration=0.9) # Generate 0.9 seconds silence
a = gensound.Sound.from_sinwave(440, duration=0.1, volume=1.0).concat(wait) # Generate 440Hz sin wave 0.1 seconds, and 0.9 seconds silence
b = gensound.Sound.from_sinwave(880, duration=1.0, volume=1.0) # Generate 880Hz sin wave 1 seconds
time_signal = gensound.concat(a, a, a, b) # Concatenate those
time_signal.write('test.wav') # Save to test.wav
time_signal.play() # Play sound