Spaces:
Sleeping
Sleeping
| 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): | |
| # Load audio files | |
| kirtan = AudioSegment.from_file(kirtan_path) | |
| tts = AudioSegment.from_file(tts_path) | |
| # Reduce kirtan volume after 4 seconds | |
| fade_point = min(fade_start, len(kirtan)) | |
| kirtan_fade = kirtan[:fade_point] + kirtan[fade_point:].apply_gain(kirtan_reduction) | |
| # Overlay TTS over faded kirtan | |
| combined = kirtan_fade.overlay(tts, position=fade_point) | |
| # Export merged file | |
| combined.export(output_path, format="mp3") | |
| def main(): | |
| st.title("Kirtan + TTS Audio Mixer") | |
| # Upload section | |
| 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"]) | |
| kirtan_files = { | |
| "Kirtan 1": "kirtan1.mp3" | |
| } | |
| if tts_file and kirtan_option: | |
| # Save uploaded TTS file | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_tts: | |
| temp_tts.write(tts_file.read()) | |
| temp_tts_path = temp_tts.name | |
| # Set paths | |
| kirtan_path = kirtan_files[kirtan_option] | |
| output_path = "merged_audio.mp3" | |
| # Process audio | |
| merge_audio(kirtan_path, temp_tts_path, output_path) | |
| # Play and download merged file | |
| st.audio(output_path, format='audio/mp3') | |
| st.download_button("Download Merged Audio", output_path, file_name="final_audio.mp3") | |
| # Cleanup temp files | |
| os.remove(temp_tts_path) | |
| if __name__ == "__main__": | |
| main() | |