|
import streamlit as st |
|
import librosa |
|
import os |
|
import time |
|
import numpy as np |
|
|
|
|
|
home_directory = os.getcwd() |
|
|
|
|
|
def ensure_directory_exists(directory): |
|
if not os.path.exists(directory): |
|
os.makedirs(directory) |
|
|
|
|
|
def process_audio(file_path): |
|
|
|
os.chdir(home_directory) |
|
|
|
file_name_without_ext = os.path.splitext(os.path.basename(file_path))[0] |
|
|
|
|
|
output_dir = os.path.join('basic_splits', file_name_without_ext) |
|
ensure_directory_exists(output_dir) |
|
os.chdir('basic_splits') |
|
from moonarch_basic import BasicSplitter |
|
splitter = BasicSplitter(file_path) |
|
splitter.run() |
|
st.write("Basic split process completed.") |
|
os.chdir(home_directory) |
|
|
|
|
|
ensure_directory_exists(os.path.join('basic_splits', 'vocal_remover', file_name_without_ext)) |
|
os.chdir(os.path.join('basic_splits', 'vocal_remover', file_name_without_ext)) |
|
from moonarch_vocal_remover import VocalRemover |
|
music_sep = VocalRemover(file_path) |
|
music_sep.run() |
|
st.write("Vocal remover process completed.") |
|
os.chdir(home_directory) |
|
|
|
return [ |
|
os.path.join('basic_splits', file_name_without_ext, 'vocals.wav'), |
|
os.path.join('basic_splits', 'vocal_remover', file_name_without_ext, 'accompaniment.wav'), |
|
os.path.join('basic_splits', file_name_without_ext, 'bass.wav'), |
|
os.path.join('basic_splits', file_name_without_ext, 'drums.wav') |
|
] |
|
|
|
|
|
st.title('Moonarch Music Analysis') |
|
st.header("Experience the Future of Sound") |
|
st.write(""" |
|
Everything you need to create and release your music, including samples, plugins, unlimited distribution, and the world's best AI mastering engine. |
|
""") |
|
|
|
|
|
if st.button("Start using Moonarch"): |
|
st.write("Welcome to Moonarch! Let's start creating amazing music.") |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload a song", type=["mp3", "wav"]) |
|
|
|
if uploaded_file is not None: |
|
st.write("File uploaded successfully.") |
|
|
|
|
|
progress_bar = st.progress(0) |
|
|
|
|
|
audio_file_path = os.path.join(home_directory, f'{uploaded_file.name}') |
|
with open(audio_file_path, 'wb') as f: |
|
f.write(uploaded_file.getbuffer()) |
|
|
|
|
|
for percent_complete in range(100): |
|
time.sleep(0.01) |
|
progress_bar.progress(percent_complete + 1) |
|
|
|
st.write("File processing complete.") |
|
|
|
if st.button('Basic Split'): |
|
with st.spinner('Splitting audio...'): |
|
output_files = process_audio(audio_file_path) |
|
|
|
st.success('Audio processed successfully!') |
|
|
|
|
|
for file in output_files: |
|
if os.path.isfile(file): |
|
file_name = os.path.basename(file) |
|
if 'vocals.wav' in file_name: |
|
st.write('Vocal') |
|
elif 'bass.wav' in file_name: |
|
st.write('Bass') |
|
elif 'drums.wav' in file_name: |
|
st.write('Drums') |
|
elif 'accompaniment.wav' in file_name: |
|
st.write('Music') |
|
|
|
st.audio(file) |
|
with open(file, 'rb') as f: |
|
st.download_button( |
|
label=f'Download {file_name}', |
|
data=f, |
|
file_name=file_name, |
|
mime='audio/wav' |
|
) |
|
else: |
|
st.error(f"Error: {file} not found.") |
|
st.write(f"Expected location: {file}") |
|
|