Text-to-Speech
Kyrgyz
File size: 1,293 Bytes
6703e27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import subprocess

def run_tts():
    st.title("Matcha TTS Interface")


    speaking_rate = st.slider("Select Speaking Rate", min_value=0.1, max_value=2.0, value=0.8, step=0.1)


    text = st.text_input("Enter text for speech synthesis:")


    if st.button("Generate Speech"):
        if text:  
            command = f"matcha-tts --speaking_rate {speaking_rate} --text \"{text}\""

            result = subprocess.run(command, shell=True, text=True, capture_output=True)
            

            audio_filename = "utterance_001.wav"
            

            if result.returncode == 0: 
                st.success("Speech generated successfully:")
                # Воспроизведение аудио
                audio_file = open(audio_filename, 'rb')
                audio_bytes = audio_file.read()
                st.audio(audio_bytes, format='audio/wav', start_time=0)
                audio_file.close()
            else:
                if result.stdout:
                    st.text(result.stdout)
                if result.stderr:
                    st.error("Error in command execution:")
                    st.text(result.stderr)
        else:
            st.error("Please enter text to synthesize.")


if __name__ == "__main__":
    run_tts()