2

How can i code a audio file compressor in python ?? Below i made a voice recorder but now i want to compress that recorded voice file.

import sounddevice as sd
from scipy.io.wavfile import write
import wavio as wv

freq = 44100
duration = 180

recording = sd.rec(int(duration * freq),
                   samplerate=freq, channels=2)

sd.wait()

write("recording0.mp3", freq, recording)

Currently i am using above code for recording audio. Then audio recorded is stored in file named recording0.mp3. But this file is of 60MB. I want to compress it so what is the code for compressing this file in python ??

yash
  • 35
  • 1
  • 6
  • See if it solves your problem [Python library for converting files to MP3 and setting their quality](https://stackoverflow.com/questions/1246131/python-library-for-converting-files-to-mp3-and-setting-their-quality) – iadi7ya Oct 18 '20 at 13:04
  • My file is already mp3 and i want to compress it. Like i used this link https://www.onlineconverter.com/compress-mp3 and it compresses my 60Mb FILE TO 1MB file. But i am not aware of the code behind it – yash Oct 18 '20 at 13:16
  • As the name implies, `scipy.io.wavfile.write` writes a wave file. It doesn't write an mp3. Just because you put ".mp3" as the extension, doesn't mean it will write an mp3. What you're writing is an uncompressed wav file with ".mp3" at the end of the name. The fact that it's 60MB is also a big indicator that you're dealing with a wav, rather than an mp3. – Paul M. Oct 18 '20 at 13:58
  • 1
    But still question is not what is the extension of the file doubt is how to compress it. – yash Oct 19 '20 at 10:51

0 Answers0