I need to convert bytes mp3 data to bytes ogg. How a can do it in python? I've seen many examples to convert it from a file, but i don't want to write it to disk.
from urllib.request import urlopen
bytes = urlopen("https://url.com/file.mp3").read()
You can use online-convert service. It has it's own API and it supports conversion directly from URL, so you don't even need to read the file into memory.
import tempfile
from pydub import AudioSegment
from urllib.request import urlopen
data = urlopen('https://sample-videos.com/audio/mp3/crowd-cheering.mp3').read()
f = tempfile.NamedTemporaryFile(delete=False)
f.write(data)
AudioSegment.from_mp3(f.name).export('result.ogg', format='ogg')
f.close()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.