Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import outetts
|
| 3 |
from scipy.io.wavfile import write
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Initialize model configuration
|
| 6 |
model_config = outetts.HFModelConfig_v1(
|
|
@@ -17,15 +20,26 @@ st.write("Enter text below to generate speech.")
|
|
| 17 |
|
| 18 |
# Sidebar for reference voice
|
| 19 |
st.sidebar.title("Voice Cloning")
|
| 20 |
-
reference_audio = st.sidebar.file_uploader("Upload a reference audio (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
if reference_audio:
|
| 23 |
-
ref_audio_path =
|
| 24 |
-
with open(ref_audio_path, "wb") as f:
|
| 25 |
-
f.write(reference_audio.read())
|
| 26 |
else:
|
| 27 |
ref_audio_path = None
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
text_input = st.text_area("Text to convert to speech:", "Hello, this is an AI-generated voice.")
|
| 30 |
|
| 31 |
if st.button("Generate Speech"):
|
|
@@ -46,3 +60,7 @@ if st.button("Generate Speech"):
|
|
| 46 |
# Play the audio in the Streamlit app
|
| 47 |
st.audio(output_path, format="audio/wav")
|
| 48 |
st.success("Speech generated successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import outetts
|
| 3 |
from scipy.io.wavfile import write
|
| 4 |
+
import tempfile
|
| 5 |
+
import os
|
| 6 |
+
from pydub import AudioSegment
|
| 7 |
|
| 8 |
# Initialize model configuration
|
| 9 |
model_config = outetts.HFModelConfig_v1(
|
|
|
|
| 20 |
|
| 21 |
# Sidebar for reference voice
|
| 22 |
st.sidebar.title("Voice Cloning")
|
| 23 |
+
reference_audio = st.sidebar.file_uploader("Upload a reference audio (any format)", type=["wav", "mp3", "ogg", "flac", "m4a"])
|
| 24 |
+
|
| 25 |
+
# Function to convert audio to WAV format
|
| 26 |
+
def convert_to_wav(audio_file):
|
| 27 |
+
temp_audio = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
| 28 |
+
audio = AudioSegment.from_file(audio_file)
|
| 29 |
+
audio.export(temp_audio.name, format="wav")
|
| 30 |
+
return temp_audio.name
|
| 31 |
|
| 32 |
if reference_audio:
|
| 33 |
+
ref_audio_path = convert_to_wav(reference_audio)
|
|
|
|
|
|
|
| 34 |
else:
|
| 35 |
ref_audio_path = None
|
| 36 |
|
| 37 |
+
# Recording functionality
|
| 38 |
+
if ref_audio_path is None:
|
| 39 |
+
st.sidebar.write("Or record your voice below:")
|
| 40 |
+
if st.sidebar.button("Record Voice"):
|
| 41 |
+
st.sidebar.warning("Recording functionality not implemented yet. Please upload a file.")
|
| 42 |
+
|
| 43 |
text_input = st.text_area("Text to convert to speech:", "Hello, this is an AI-generated voice.")
|
| 44 |
|
| 45 |
if st.button("Generate Speech"):
|
|
|
|
| 60 |
# Play the audio in the Streamlit app
|
| 61 |
st.audio(output_path, format="audio/wav")
|
| 62 |
st.success("Speech generated successfully!")
|
| 63 |
+
|
| 64 |
+
# Clean up temporary files
|
| 65 |
+
if ref_audio_path:
|
| 66 |
+
os.remove(ref_audio_path)
|