簡體   English   中英

如何將wav文件的內容放入數組,以便剪切所需的段並將其轉換為使用python的wav格式?

[英]How to get the contents of the wav file into array so as to cut the required segment and convert it back to wav format using python?

如何將wav文件的內容放入數組,以便剪切所需的段並將其轉換為使用python的wav格式? 我的概率類似於“ ROMANs”概率,我在此站點的帖子中已經看到過。

基本上,我想將不同的WAV文件的一部分合並為一個WAV文件? 如果沒有其他解決方案,則將內容分成數組和剪切部分,然后合並並再次轉換bac? 請建議...

編輯:

我更喜歡將wave文件的內容解壓縮到一個數組中,並通過從wav文件中剪切所需的聲音片段來進行編輯,因為我正在進行語音處理,因此我猜想這種方式以后會很容易提高聲音的質量。 。

可以建議一種方法嗎? 請幫助

提前致謝。

通常,有一些庫可用於處理媒體文件。 pymedia 但是,如果您只需要支持簡單的WAV,則可以使用內置的wave模塊。

import wave
win= wave.open('sample.wav', 'rb')
wout= wave.open('segment.wav', 'wb')

t0, t1= 1.0, 2.0 # cut audio between one and two seconds
s0, s1= int(t0*win.getframerate()), int(t1*win.getframerate())
win.readframes(s0) # discard
frames= win.readframes(s1-s0)

wout.setparams(win.getparams())
wout.writeframes(frames)

win.close()
wout.close()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM