首页 > 解决方案 > converting audio file and return it

问题描述

I'm trying to convert an mp3 file to wav file. using the following code

def change_file(file):
    print(file)
    wav='fff'+'.wav'
    print('here ')
    mp3_file=file
    sound=pydub.AudioSegment.from_mp3(mp3_file)
    sound=sound.set_frame_rate(8000)
    temp=sound.export(wav, format="wav")

    return temp//doesnt work

the sound.export saves the file on my machine I don't want it to be saved I want to return it immediately cause I am using this code as an API in Django so my goal is to except a file and convert it then return it

标签: pythonffmpeg

解决方案


假设我正确理解了您的问题:您机器上的文件中本地存储了数据,您可以使用 pydub 读取并使用 pydub 进行转换。并且您希望 Django API 提供的数据(而不是文件)在客户端检索它。

因此,您应该从 Django(服务器端)序列化您的数据,使其从 API 可用,从客户端检索它,并从客户端反序列化它。


推荐阅读