| import streamlit as st |
| from pydub import AudioSegment |
| import tempfile |
| import os |
|
|
| def merge_audio(kirtan_path, tts_path, output_path, fade_start=4000, kirtan_reduction=-15, tts_start_offset=0): |
| """Merges kirtan and TTS audio with adjustable fade-in and offset.""" |
| kirtan = AudioSegment.from_file(kirtan_path) |
| tts = AudioSegment.from_file(tts_path) |
| |
| |
| fade_point = min(fade_start, len(kirtan)) |
| kirtan_fade = kirtan[:fade_point] + kirtan[fade_point:].apply_gain(kirtan_reduction) |
| |
| |
| combined = kirtan_fade.overlay(tts, position=fade_point + tts_start_offset) |
| |
| |
| combined.export(output_path, format="mp3") |
|
|
| def main(): |
| st.title("Kirtan + TTS Audio Mixer with Adjustable Timing") |
| |
| |
| tts_file = st.file_uploader("Upload TTS Audio (MP3 or WAV)", type=["mp3", "wav"]) |
| kirtan_option = st.selectbox("Select a Kirtan:", ["Kirtan 1", "Kirtan 2", "Kirtan 3"]) |
| |
| |
| fade_start = st.slider("Kirtan Fade Start (ms)", min_value=1000, max_value=10000, value=4000, step=500) |
| tts_start_offset = st.slider("TTS Start Offset (ms)", min_value=0, max_value=5000, value=0, step=100) |
| kirtan_reduction = st.slider("Kirtan Volume Reduction (dB)", min_value=-30, max_value=0, value=-15, step=1) |
| |
| kirtan_files = { |
| "Kirtan 1": "kirtan1.mp3", |
| "Kirtan 2": "kirtan2.mp3", |
| "Kirtan 3": "kirtan3.mp3" |
| } |
| |
| if tts_file and kirtan_option: |
| |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_tts: |
| temp_tts.write(tts_file.read()) |
| temp_tts_path = temp_tts.name |
| |
| |
| kirtan_path = kirtan_files[kirtan_option] |
| output_path = "merged_audio.mp3" |
| |
| |
| merge_audio(kirtan_path, temp_tts_path, output_path, fade_start, kirtan_reduction, tts_start_offset) |
| |
| |
| st.audio(output_path, format='audio/mp3') |
| st.download_button("Download Merged Audio", output_path, file_name="final_audio.mp3") |
| |
| |
| os.remove(temp_tts_path) |
|
|
| if __name__ == "__main__": |
| main() |
|
|