FFmpeg works on Pipe protocols, and the same functionality has been ported to ffmpy so data can be written to stdin and read from stdout. You would likely have to provide some timing constructs as well to handle synchronization and appropriate buffer managment, but I see no reason this couldn't be made to work.
ffmpy: using the pipe protocol
live audio streaming with FFmpeg on a rasberry pi
Answer from Aaron on Stack OverflowAudio Compressor in Python - Stack Overflow
Open Source Audio Compressor/Limiter Library for Python
python - Fast way to compress audio data? - Stack Overflow
Python library for stabilizing the volume of audio files?
» pip install CaaS
I have audio files that vary heavily in volume, and I would like to make a program that modifies the volume and outputs a new file. Is this possible in Python?
Edit: What I mean is not just uniformly reducing the volume of one audio file, there are some parts where it is very loud and some inaudible parts. I would like a library where I would be able to analyze and bring only those parts closer to the middle range.
import time, sys,io
import pymedia.audio.sound as sound
import pymedia.audio.acodec as acodec
import pymedia.muxer as muxer
def voiceRecorder( secs, name ):
f = open(name,'wb')
secs = secs*5
dm= muxer.Demuxer('mp3')
snds= sound.getODevices()
rt = 44100
cparams= { 'id': acodec.getCodecID( 'mp3' ),
'bitrate': 128000/4,
'sample_rate': rt,
'channels': 2 }
ac= acodec.Encoder( cparams )
snd= sound.Input( rt, 2, sound.AFMT_S16_LE )
snd.start()
start_time = time.time()
while snd.getPosition()<= secs:
s= snd.getData()
if s and len( s ):
for fr in ac.encode( s ):
f.write( fr)
else:
time.sleep(.25)
snd.stop()
if __name__ == "__main__":
if len( sys.argv )!= 3:
print 'Usage: voice_recorder <seconds> <file_name>'
else:
voiceRecorder( int( sys.argv[ 1 ] ), sys.argv[ 2 ] )
Wow for my calculations are you sending a little more that 2KB, to be exact 2.0480KB of audio at every loop to your socket connection:
(16 * 44.1 / 8) * 1024/44100 = 2.0480
One simple way to send less data is reducing the chunk size if you change the chunk to 512 now are you sending just a bit more that 1KB.
Another way is try use zlib package in python to compress the stream.read data after send it through your socket, but for it do not forget to unzip in the other side.