File size: 2,008 Bytes
a6b8c53
8460a05
 
 
a6b8c53
8460a05
 
 
 
 
 
 
 
 
2498228
8460a05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
import base64
from io import BytesIO

# Backend API URL
API_URL = "https://www.neuralaudio.solutions/api/zyphra-tts"

st.set_page_config(page_title="NeuralAudioAI TTS", layout="centered")
st.image("https://storage.googleapis.com/crypto-utils-1/Header%20with%20Pattern.png", use_container_width=True)
st.title("πŸ”Š Neural Audio AI - TTS Demo")
st.write("Enter text and generate speech using **NeuralAudioAI/NA_base**.")

# Text Input
text = st.text_area("πŸ“ Enter text to synthesize:", "Hello! This is Neural Audio AI speaking. How may I help you today?")

if st.button("πŸŽ™οΈ Generate Speech"):
    if not text.strip():
        st.warning("⚠️ Please enter some text.")
    else:
        with st.spinner("Generating audio... 🎢"):
            try:
                # Mimic the working frontend FormData:
                # - "text" field with the text value.
                # - "speaker_audio" left empty so backend uses its default.
                files = {
                    "text": (None, text),
                    "speaker_audio": (None, "")  # This will be treated as not provided.
                }
                
                response = requests.post(API_URL, files=files)
                
                if response.status_code == 200:
                    audio_bytes = response.content
                    
                    # Use BytesIO so st.audio plays the file directly from memory.
                    audio_io = BytesIO(audio_bytes)
                    st.audio(audio_io, format="audio/mpeg")
                else:
                    try:
                        error_message = response.json().get("error", "Unknown error occurred")
                    except Exception:
                        error_message = response.text
                    st.error(f"❌ Failed to generate speech: {error_message}")
            except requests.RequestException as e:
                st.error(f"❌ Error communicating with the server: {e}")