Quantcast
Viewing all articles
Browse latest Browse all 3

python ringtone maker : how to split files

I'm writing an application for making ringtones for the iPhone. It's just for fun.Here's what I've done till now. (Mind you, i'm a beginner in Python !)So I open my mp3 file in binary mode. read the whole file. Convert it into a list. Use list slicing to split the file. Save this new split into a new mp3 file. This works fine. I however want to the ringtones to have a max of 30 seconds play time and I want the user to choose what portion of the file he wants as the ringtone. Can anyone guide me in the right direction ? Thanks

Here's my code till now :

f = open("Bruno Mars - Locked Out Of Heaven [OFFICIAL VIDEO].mp3", 'rb').read()mp3 = list(f)fo = open("newFile.mp3", "wb")print(mp3[0:1300000]) fo.write(bytes(mp3[0:1300000]))

Here's what I got after some coding:

import osf = open("Bruno Mars - Locked Out Of Heaven [OFFICIAL VIDEO].mp3", 'rb').read()fileSize = os.path.getsize("Bruno Mars - Locked Out Of Heaven [OFFICIAL VIDEO].mp3")print("Size of the whole file",fileSize)mp3 = list(f)bitRate = int(input("Enter the bit rate of your file"))size_mbps = bitRate*(15/2048)print("MB per minute :",size_mbps)second_size = int((size_mbps/60)*(10**6))print("Size of each second :",second_size)start_length = int(input("Enter the start time (in seconds)"))end_length = int(input("Enter the end time (in seconds)"))start_size = int(second_size*start_length)end_size = int(second_size*end_length)fo = open("newFile.mp3", "wb")fo.write(bytes(mp3[start_size:end_size]))

It works fine but I need to tweak it a little more. Any input on this code ?


Viewing all articles
Browse latest Browse all 3

Trending Articles