First version
Browse files- app.py +22 -14
- requirements.txt +2 -1
app.py
CHANGED
@@ -28,29 +28,37 @@ default_text_dict = {
|
|
28 |
'JP': 'ใใญในใ่ชญใฟไธใใฎๅ้ใฏๆ่ฟๆฅ้ใช็บๅฑใ้ใใฆใใพใ',
|
29 |
'KR': '์ต๊ทผ ํ
์คํธ ์์ฑ ๋ณํ ๋ถ์ผ๊ฐ ๊ธ์๋๋ก ๋ฐ์ ํ๊ณ ์์ต๋๋ค.',
|
30 |
}
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
def synthesize(text, speaker, speed, language, progress=gr.Progress()):
|
33 |
bio = io.BytesIO()
|
34 |
models[language].tts_to_file(text, models[language].hps.data.spk2id[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
|
35 |
return bio.getvalue()
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
return gr.update(value=list(models[language].hps.data.spk2id.keys())[0], choices=list(models[language].hps.data.spk2id.keys())), newtext
|
42 |
with gr.Blocks() as demo:
|
43 |
-
gr.Markdown('#
|
44 |
with gr.Group():
|
45 |
-
speaker = gr.Dropdown(speaker_ids.keys(), interactive=True, value='
|
46 |
-
language = gr.Radio(['EN', 'ES', 'FR', 'ZH', 'JP', 'KR'], label='Language', value='
|
47 |
speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
|
48 |
-
|
49 |
-
language.input(load_speakers, inputs=[language
|
50 |
-
|
|
|
|
|
51 |
aud = gr.Audio(interactive=False)
|
|
|
52 |
btn.click(synthesize, inputs=[text, speaker, speed, language], outputs=[aud])
|
53 |
-
gr.Markdown('Demo by [
|
54 |
|
55 |
|
56 |
demo.queue(api_open=True, default_concurrency_limit=10).launch(show_api=True)
|
|
|
28 |
'JP': 'ใใญในใ่ชญใฟไธใใฎๅ้ใฏๆ่ฟๆฅ้ใช็บๅฑใ้ใใฆใใพใ',
|
29 |
'KR': '์ต๊ทผ ํ
์คํธ ์์ฑ ๋ณํ ๋ถ์ผ๊ฐ ๊ธ์๋๋ก ๋ฐ์ ํ๊ณ ์์ต๋๋ค.',
|
30 |
}
|
31 |
+
def extract_text(file):
|
32 |
+
from pypdf import PdfReader
|
33 |
+
reader = PdfReader(file)
|
34 |
+
number_of_pages = len(reader.pages)
|
35 |
+
text = ''.join(page.extract_text() for page in reader.pages[:10])
|
36 |
+
return text
|
37 |
+
|
38 |
def synthesize(text, speaker, speed, language, progress=gr.Progress()):
|
39 |
bio = io.BytesIO()
|
40 |
models[language].tts_to_file(text, models[language].hps.data.spk2id[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
|
41 |
return bio.getvalue()
|
42 |
+
|
43 |
+
def load_speakers(language):
|
44 |
+
return gr.update(value=list(models[language].hps.data.spk2id.keys())[0], choices=list(models[language].hps.data.spk2id.keys()))
|
45 |
+
|
46 |
+
|
|
|
47 |
with gr.Blocks() as demo:
|
48 |
+
gr.Markdown('# PDF reader\n\nA real pdf reader based on [MeloTTS](https://github.com/myshell-ai/MeloTTS).')
|
49 |
with gr.Group():
|
50 |
+
speaker = gr.Dropdown(speaker_ids.keys(), interactive=True, value='FR', label='Speaker')
|
51 |
+
language = gr.Radio(['EN', 'ES', 'FR', 'ZH', 'JP', 'KR'], label='Language', value='FR')
|
52 |
speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
|
53 |
+
file = gr.File(label="Document ร lire")
|
54 |
+
language.input(load_speakers, inputs=[language], outputs=[speaker])
|
55 |
+
btn_extract = gr.Button('Extraire le texte', variant='primary')
|
56 |
+
text = gr.Textbox(label="Texte extrait")
|
57 |
+
btn = gr.Button('Rรฉciter le texte !', variant='primary')
|
58 |
aud = gr.Audio(interactive=False)
|
59 |
+
btn_extract.click(extract_text, inputs=[file], outputs=[text])
|
60 |
btn.click(synthesize, inputs=[text, speaker, speed, language], outputs=[aud])
|
61 |
+
gr.Markdown('Demo by [m-ric](https://x.com/AymericRoucher).')
|
62 |
|
63 |
|
64 |
demo.queue(api_open=True, default_concurrency_limit=10).launch(show_api=True)
|
requirements.txt
CHANGED
@@ -28,4 +28,5 @@ langid==1.1.6
|
|
28 |
tqdm
|
29 |
tensorboard==2.16.2
|
30 |
loguru==0.7.2
|
31 |
-
txtsplit
|
|
|
|
28 |
tqdm
|
29 |
tensorboard==2.16.2
|
30 |
loguru==0.7.2
|
31 |
+
txtsplit
|
32 |
+
pypdf
|