File size: 1,732 Bytes
467c7a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c9eccf
467c7a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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()