File size: 2,421 Bytes
aaed37a 2158d6f f034b93 4851afd aaed37a 2158d6f 4851afd 6a86f73 4851afd 20d8ce9 4851afd 20d8ce9 4851afd 20d8ce9 4851afd f034b93 6a86f73 20d8ce9 4851afd 20d8ce9 4851afd f034b93 4851afd 6a86f73 4851afd 6a86f73 4851afd 6a86f73 4851afd 6a86f73 4851afd 6a86f73 4851afd 6a86f73 4851afd 6a86f73 4851afd aaed37a 4851afd aaed37a 4851afd 6a86f73 4851afd 20d8ce9 4851afd f034b93 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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):
# Load the audio file
y, sr = librosa.load(audio_file)
# Pitch shift using librosa (female voice typically higher pitch)
y_shifted = librosa.effects.pitch_shift(y, sr=sr, n_steps=pitch_factor)
# Apply some feminine characteristics
# Smooth the audio slightly
y_smooth = librosa.effects.preemphasis(y_shifted)
# Normalize audio
y_normalized = librosa.util.normalize(y_smooth)
return y_normalized, sr
def save_audio(audio_data, sr):
# Save processed audio to BytesIO object
buffer = BytesIO()
sf.write(buffer, audio_data, sr, format='WAV')
return buffer
st.title("Voice Changer - Female Voice Conversion")
# File uploader
uploaded_file = st.file_uploader("Upload an audio file", type=['wav', 'mp3'])
if uploaded_file is not None:
# Save uploaded file temporarily
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmp_file:
tmp_file.write(uploaded_file.getvalue())
tmp_path = tmp_file.name
# Pitch adjustment slider
pitch_factor = st.slider("Pitch Adjustment", 0.0, 12.0, 8.0, 0.5)
if st.button("Convert to Female Voice"):
# Process the audio
try:
processed_audio, sr = process_audio(tmp_path, pitch_factor)
# Save processed audio
audio_buffer = save_audio(processed_audio, sr)
# Create download button
st.audio(audio_buffer, format='audio/wav')
# Add download button
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)}")
# Add instructions
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
""") |