我尝试使用声音文件库将电报语音文件保存在wave音频文件中:
import numpy as np
l = [5,6,4,7,11,14,12,1,3]
l_sort = np.sort(l) #sorting elements of the list
evens = list(filter(lambda x: x%2==0, l_sort)) #extract even elements
odds = list(filter(lambda x: x%2!=0, l_sort)) #extract odd elements
out = evens + odds
但我收到以下错误:
def ReceiveVoice(bot, update, user_data):
voice = bot.getFile(update.message.voice.file_id)
voice.download('file.ogg')
data, samplerate = sf.read('file.ogg')
sf.write('file.wav', data, samplerate)
答案 0 :(得分:0)
您可以尝试使用ffmpeg从ogg
转换为wav
,方法是使用python的模块子进程执行以下命令行。
import subprocess
src_filename = 'captured.ogg'
dest_filename = 'output.wav'
process = subprocess.run(['ffmpeg', '-i', src_filename, dest_filename])
if process.returncode != 0:
raise Exception("Something went wrong")
答案 1 :(得分:0)
尝试一下
import soundfile as sf
data, samplerate = sf.read(input_ogg)
sf.write(output_wav, data, samplerate)