本文介绍了如何创建使用numpy的数组pydub AudioSegment?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在蟒蛇以下code
I have the following code in python
from scipy.io.wavfile import read
rate, signal = read('./data/input.wav')
# get only one channel
signal = signal[:,0]
# do a bunch of processing here
现在我想创建一个pydub段使用信号和速度
Now I want to create an pydub segment using 'signal' and 'rate'
audio_segment = pydub.AudioSegment()
那么,如何可以创建这个音频片段,在那之后,
我怎样才能找回我的信号作为numpy的阵列?
So how can I create this audio segment, and after that, how can I get back my signal as an numpy array?
推荐答案
我能在我的机器上运行此code:
I was able to run this code on my machine:
from scipy.io.wavfile import read
from pydub import AudioSegment
rate, signal = read("./test/data/test1.wav")
channel1 = signal[:,0]
audio_segment = pydub.AudioSegment(
channel1.tobytes(),
frame_rate=rate,
sample_width=channel1.dtype.itemsize,
channels=1
)
# test that it sounds right (requires ffplay, or pyaudio):
from pydub.playback import play
play(audio_segment)
这篇关于如何创建使用numpy的数组pydub AudioSegment?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!