from turtle import onclick import streamlit as st from pydub import AudioSegment import pydub from pydub.playback import play from scipy.io import wavfile from os import path import os st.title("Audio Format Converter...") upfile = st.file_uploader("Choose a Audio file",type=['.mp3', '.wav', '.ogg','.raw','.flac','.3gp','.3g']) st.write(upfile) from playsound import playsound # @st.cache def load_audio(audio): au = st.audio(audio,format = 'audio/wav') return au def conv(audio,title,to): st.title(audio) sound = AudioSegment.from_mp3(audio) export = "converted Audios/"+title+"."+to st.title(export) sound.export(export, format="wav") st.success("Audio Successfuly Converted And saved in converted Audios folder") if upfile is not None: file_details = {"filename":upfile.name,"type":upfile.type} # path = os.getcwd() st.write(file_details) st.write(upfile) audio = load_audio(upfile) with open(os.path.join("file uploaded",upfile.name),"wb") as f: f.write(upfile.getbuffer()) try: # from1 = st.selectbox( # 'What is your current file format?', # ('.mp3', '.wav', '.ogg','.raw','.flac','.3gp','.3g')) title = st.text_input('Rename Audio', '') # st.write('New Name For This Audio', title) to = st.selectbox( 'In which format you want to convert?', ('mp3', 'wav', 'ogg','raw','flac','3gp','3g')) file = "file uploaded/"+upfile.name if st.button("Convert"): conv(file,title,to) except: st.write("Please Upload your Audio File To continue")