示例#1
0
 def make_tone(self, freq):
     if self.waveEntry.get() == "Sine":
         tone = (Sine(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     elif self.waveEntry.get() == "Square":
         tone = (Square(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     elif self.waveEntry.get() == "Triangle":
         tone = (Triangle(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     elif self.waveEntry.get() == "Sawtooth":
         tone = (Sawtooth(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     elif self.waveEntry.get() == "Pulse":
         tone = (Pulse(freq).to_audio_segment(
             duration=int(self.durEntry.get())).fade_out(
                 self.slider.get()).fade_in(self.slider2.get())).apply_gain(
                     self.slider3.get()) + self.slider4.get()
     play(tone)
示例#2
0
    def test_with_smoke(self):
        Sine(440).to_audio_segment()
        Square(440).to_audio_segment()
        Triangle(440).to_audio_segment()

        Pulse(440, duty_cycle=0.75).to_audio_segment()
        Sawtooth(440, duty_cycle=0.75).to_audio_segment()

        WhiteNoise().to_audio_segment()
#!/usr/bin/env python

from pydub.generators import Pulse

# Create 10 seconds of audio
audio = Pulse(440, duty_cycle=0.6).to_audio_segment() * 10

# Fade it in and out
faded = audio.fade_in(2500).fade_out(5000)

# Save it
faded.export("test_audio.mp3", format="mp3")