我希望在播放之前更改声音值,然后再播放

时间:2017-07-10 21:55:51

标签: python audio playback pyaudio

我实时录制信号,然后立即播放。然而, 我希望在播放之前更改声音值,然后再播放。 这是我的代码:

    import pyaudio
    import time
    import numpy 
    import sys
    import sounddevice as sd


    WIDTH = 2
    CHANNELS = 2
    RATE = 44100
    chunk=1024

    p = pyaudio.PyAudio()

    def callback(in_data, frame_count, time_info, status):



   return (in_data, pyaudio.paContinue)

   stream = p.open(format=p.get_format_from_width(WIDTH),
            channels=CHANNELS,
            rate=RATE,
            frames_per_buffer=chunk,
            input=True,
            output=True,
            stream_callback=callback)






      stream.start_stream()

      while stream.is_active():
      time.sleep(0.1)

      stream.stop_stream()
      stream.close()

      p.terminate()

我找到了这段代码,但是通过代码连接我的代码有问题,有人可以告诉我如何解决这个问题

   # This function changes the volume of a sound
   # A factor > 1 increases the volume
   # A factor < 1 decreases the volume
   def changeVolume(sound, factor):
   newSound = duplicateSound(sound)
   for sample in getSamples(newSound):
   value = getSampleValue(sample)
   setSampleValue(sample, value * factor)
   return newSound

0 个答案:

没有答案