I am experimenting with pydub, which I really like, however I am having a problem when splitting / combining an mp3 file.
I need to create a series of small pieces of audio on a server that will be sent sequentially to a web browser and played using an element <audio/>. I need the sound reproduction to be “seamless” without audible associations between the individual fragments. At the moment, however, the connections between the individual bits of sound are quite obvious, sometimes there is a short silence, and sometimes a strange sound failure.
<audio/>
In my proof of concept code, I took one big mp3 and split it into 1 second chunks as follows:
song = AudioSegment.from_mp3('my.mp3') song_pos = 0 while song_pos < 100: p1 = song_pos * 1000 p2 = p1 + 1000 segment = song[p1:p2] # 1 second of audio output = StringIO.StringIO() segment.export(output, format="mp3") client_data = output.getvalue() # send this to client song_pos += 1
client_data http-:
socket.send("HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Type: audio/mp3\r\n\r\n")
socket.send(client_data)
- , , ?
:
, MP3, ffmpeg, ( ).
, , wave, gzip . (, flac), , , , .
, , , , . 100 (), . MP3 , . , 1 - "" ( ) - (, 20 50 , "".
() , " " ( , , ) .
, , :
( ) . - (CBR), 1- , . , 256 / CBR, 256 .
, , , . ,
p2 = p1 + 1001
, . .
, , , . raw_data AudioSegment() .
- , , ; , .
I am not familiar with this software, but when coding Niels Werner's sentences, you can try:
song = AudioSegment.from_mp3('my.mp3') song_pos = 0 # begin with a millisecond of blank segment = AudioSegment.silent(duration=1) # append all your pieces to it while song_pos < 100: p1 = song_pos * 1000 p2 = p1 + 1000 #append an item to your segment with several milliseconds of crossfade segment.append(song[p1:p2], crossfade=50) song_pos += 1 # then pass it on to your client outside of your loop output = StringIO.StringIO() segment.export(output, format="mp3") client_data = output.getvalue() # send this to client
depending on how low / high the frequency of what you are connecting to, you need to adjust the crossfade time for mixing; low frequency will require more fading.
Source: https://habr.com/ru/post/1671690/More articles:I got error 530 5.7.0 from gmail server trying to send an email from Arduino and Ethernet screen - smtpSet user oracle password expiration / grace period - oracleImageView scaleType = "fitXY" не работает в пред-леллиповом устройстве внутри Cardviewag grid pagination does not work, initially making a server call twice - angularMC9S08QD4 - присвоение удвоению/длинам "развращает" несвязанные переменные - cReturn empty observable from Angular2 service - angularsmooth nested object with lodash - javascriptVue.js anchor for div inside the same component - htmlGet all child value on label in table cell - iosWhy does EF 6 ignore applied migrations if I move the Migrations folder? - c #All Articles