| | import streamlit as st |
| | import librosa |
| | import soundfile as sf |
| | import numpy as np |
| | from io import BytesIO |
| | import tempfile |
| |
|
| | def process_audio(audio_file, pitch_factor=8): |
| | |
| | y, sr = librosa.load(audio_file) |
| | |
| | |
| | y_shifted = librosa.effects.pitch_shift(y, sr=sr, n_steps=pitch_factor) |
| | |
| | |
| | |
| | y_smooth = librosa.effects.preemphasis(y_shifted) |
| | |
| | |
| | y_normalized = librosa.util.normalize(y_smooth) |
| | |
| | return y_normalized, sr |
| |
|
| | def save_audio(audio_data, sr): |
| | |
| | buffer = BytesIO() |
| | sf.write(buffer, audio_data, sr, format='WAV') |
| | return buffer |
| |
|
| | st.title("Voice Changer - Female Voice Conversion") |
| |
|
| | |
| | uploaded_file = st.file_uploader("Upload an audio file", type=['wav', 'mp3']) |
| |
|
| | if uploaded_file is not None: |
| | |
| | with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmp_file: |
| | tmp_file.write(uploaded_file.getvalue()) |
| | tmp_path = tmp_file.name |
| |
|
| | |
| | pitch_factor = st.slider("Pitch Adjustment", 0.0, 12.0, 8.0, 0.5) |
| | |
| | if st.button("Convert to Female Voice"): |
| | |
| | try: |
| | processed_audio, sr = process_audio(tmp_path, pitch_factor) |
| | |
| | |
| | audio_buffer = save_audio(processed_audio, sr) |
| | |
| | |
| | st.audio(audio_buffer, format='audio/wav') |
| | |
| | |
| | st.download_button( |
| | label="Download Converted Audio", |
| | data=audio_buffer, |
| | file_name="female_voice.wav", |
| | mime="audio/wav" |
| | ) |
| | |
| | except Exception as e: |
| | st.error(f"Error processing audio: {str(e)}") |
| |
|
| | |
| | st.markdown(""" |
| | ### Instructions: |
| | 1. Upload a WAV or MP3 audio file |
| | 2. Adjust the pitch slider (higher values = more feminine voice) |
| | 3. Click 'Convert to Female Voice' |
| | 4. Play the converted audio |
| | 5. Download the result if satisfied |
| | |
| | ### Notes: |
| | - Best results with clear audio input |
| | - Recommended pitch adjustment: 6-8 for natural-sounding results |
| | - Larger files may take longer to process |
| | """) |