shukdevdatta123 commited on
Commit
385c233
ยท
verified ยท
1 Parent(s): de8d4a5

Create abc.txt

Browse files
Files changed (1) hide show
  1. abc.txt +100 -0
abc.txt ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from kokoro import KPipeline
3
+ import soundfile as sf
4
+ import io
5
+ import os
6
+
7
+ # Install espeak-ng if not installed
8
+ if not os.system("which espeak-ng"):
9
+ st.text("espeak-ng already installed.")
10
+ else:
11
+ os.system("apt-get -qq -y install espeak-ng")
12
+ st.text("Installing espeak-ng...")
13
+
14
+ # Streamlit App UI Setup
15
+ st.title("Text-to-Speech with Kokoro")
16
+ st.sidebar.header("Configuration & Instructions")
17
+
18
+ # Sidebar Instructions
19
+ st.sidebar.markdown("""
20
+ ### How to Use the Text-to-Speech App:
21
+ 1. **Enter Text**: In the main text area, input any text that you want the model to convert to speech.
22
+
23
+ 2. **Select Language**:
24
+ - Choose the language of the text you are entering. Available options include:
25
+ - ๐Ÿ‡บ๐Ÿ‡ธ American English (`a`)
26
+ - ๐Ÿ‡ฌ๐Ÿ‡ง British English (`b`)
27
+ - ๐Ÿ‡ช๐Ÿ‡ธ Spanish (`e`)
28
+ - ๐Ÿ‡ซ๐Ÿ‡ท French (`f`)
29
+ - ๐Ÿ‡ฎ๐Ÿ‡ณ Hindi (`h`)
30
+ - ๐Ÿ‡ฎ๐Ÿ‡น Italian (`i`)
31
+ - ๐Ÿ‡ง๐Ÿ‡ท Brazilian Portuguese (`p`)
32
+ - ๐Ÿ‡จ๐Ÿ‡ณ Mandarin Chinese (`z`)
33
+ - ๐Ÿ‡ฏ๐Ÿ‡ต Japanese (`j`)
34
+
35
+ 3. **Select Voice**:
36
+ - Choose the voice style for the speech. You can pick different voices based on tone and gender, such as `af_heart`, `af_joy`, etc.
37
+
38
+ 4. **Adjust Speed**:
39
+ - Use the speed slider to change how fast the speech is generated. You can set it between `0.5x` to `2.0x`, where `1.0x` is the normal speed.
40
+ 5. **Generate Speech**:
41
+ - After configuring the settings, click on the **"Generate Audio"** button. The app will process your text and produce speech audio accordingly.
42
+
43
+ 6. **Download**:
44
+ - Once the audio is generated, you can play it directly in the app or download it as a `.wav` file by clicking on the **"Download Audio"** button.
45
+ Enjoy experimenting with the text-to-speech conversion, and feel free to try different voices, speeds, and languages!
46
+ """)
47
+
48
+ # User input for text, language, and voice settings
49
+ input_text = st.text_area("Enter your text here", "The sky above the port was the color of television...")
50
+ lang_code = st.selectbox("Select Language", ['a', 'b', 'e', 'f', 'h', 'i', 'p', 'z', 'j'])
51
+ voice = st.selectbox("Select Voice", ['af_alloy', 'af_aoede', 'af_bella', 'af_heart', 'af_jessica', 'af_kore', 'af_nicole', 'af_nova', 'af_river', 'af_sarah', 'af_sky',
52
+ 'am_adam', 'am_echo', 'am_eric', 'am_fenrir', 'am_liam', 'am_michael', 'am_onyx', 'am_puck', 'am_santa',
53
+ 'bf_alice', 'bf_emma', 'bf_isabella', 'bf_lily',
54
+ 'bm_daniel', 'bm_fable', 'bm_george', 'bm_lewis',
55
+ 'ef_dora',
56
+ 'em_alex', 'em_santa',
57
+ 'ff_siwis',
58
+ 'hf_alpha', 'hf_beta',
59
+ 'hm_omega', 'hm_psi',
60
+ 'if_sara',
61
+ 'im_nicola',
62
+ 'jf_alpha', 'jf_gongitsune', 'jf_nezumi', 'jf_tebukuro',
63
+ 'jm_kumo',
64
+ 'pf_dora',
65
+ 'pm_alex', 'pm_santa',
66
+ 'zf_xiaobei', 'zf_xiaoni', 'zf_xiaoxiao', 'zf_xiaoyi',
67
+ 'zm_yunjian', 'zm_yunxi', 'zm_yunxia', 'zm_yunyang']
68
+ ) # Change voice options as per model
69
+ speed = st.slider("Speed", min_value=0.5, max_value=2.0, value=1.0, step=0.1)
70
+
71
+ # Initialize the TTS pipeline with user-selected language
72
+ pipeline = KPipeline(lang_code=lang_code)
73
+
74
+ # Generate Audio function
75
+ def generate_audio(text, lang_code, voice, speed):
76
+ generator = pipeline(text, voice=voice, speed=speed, split_pattern=r'\n+')
77
+ for i, (gs, ps, audio) in enumerate(generator):
78
+ audio_data = audio
79
+ # Save audio to in-memory buffer
80
+ buffer = io.BytesIO()
81
+ # Explicitly specify format as WAV
82
+ sf.write(buffer, audio_data, 24000, format='WAV') # Add 'format="WAV"'
83
+ buffer.seek(0)
84
+ return buffer
85
+
86
+ # Generate and display the audio file
87
+ if st.button('Generate Audio'):
88
+ st.write("Generating speech...")
89
+ audio_buffer = generate_audio(input_text, lang_code, voice, speed)
90
+
91
+ # Display Audio player in the app
92
+ st.audio(audio_buffer, format='audio/wav')
93
+
94
+ # Optional: Save the generated audio file for download
95
+ st.download_button(
96
+ label="Download Audio",
97
+ data=audio_buffer,
98
+ file_name="generated_speech.wav",
99
+ mime="audio/wav"
100
+ )