Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import librosa | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from pydub import AudioSegment | |
| from io import BytesIO | |
| from utils import apply_equalizer, apply_pitch_shift, extract_lyrics | |
| st.set_page_config(page_title="AI Singing Voice Player", layout="wide") | |
| st.title("π€ AI Singing Voice Player with Equalizer, Visualizer & Karaoke") | |
| audio_file = "audio/output.wav" | |
| y, sr = librosa.load(audio_file) | |
| # Equalizer Controls | |
| st.sidebar.header("ποΈ Equalizer & Pitch") | |
| bass_gain = st.sidebar.slider("Bass Gain (dB)", -10, 10, 0) | |
| mid_gain = st.sidebar.slider("Mid Gain (dB)", -10, 10, 0) | |
| treble_gain = st.sidebar.slider("Treble Gain (dB)", -10, 10, 0) | |
| pitch_shift_val = st.sidebar.slider("Pitch Shift (semitones)", -12, 12, 0) | |
| # Apply Equalizer and Pitch Shift | |
| y_eq = apply_equalizer(y, bass_gain, mid_gain, treble_gain, sr) | |
| y_final = apply_pitch_shift(y_eq, sr, pitch_shift_val) | |
| # Convert to playable audio | |
| audio_bytes = BytesIO() | |
| AudioSegment( | |
| y_final.tobytes(), frame_rate=sr, sample_width=2, channels=1 | |
| ).export(audio_bytes, format="wav") | |
| # Audio Player | |
| st.audio(audio_bytes, format='audio/wav') | |
| # Optional Real-time Visualizer | |
| if st.checkbox("πΆ Show Real-Time Spectrum Visualizer"): | |
| HtmlFile = open("static/visualizer.html", 'r', encoding='utf-8') | |
| source_code = HtmlFile.read() | |
| st.components.v1.html(source_code, height=350) | |
| # Optional Karaoke Lyrics Sync | |
| if st.checkbox("π€ Show Karaoke Lyrics (Optional Upload)"): | |
| lyrics_file = st.file_uploader("Upload Lyrics (.lrc or .txt)", type=["lrc", "txt"]) | |
| if lyrics_file: | |
| lyrics_text = extract_lyrics(lyrics_file) | |
| st.markdown("### π Lyrics:") | |
| st.markdown(lyrics_text, unsafe_allow_html=True) | |
| # Waveform Visualization | |
| st.subheader("Waveform Visualization") | |
| fig, ax = plt.subplots(figsize=(10, 3)) | |
| librosa.display.waveshow(y_final, sr=sr, ax=ax) | |
| st.pyplot(fig) | |