Spaces:
m-ric
/
Running on Zero

m-ric HF staff commited on
Commit
efd546f
โ€ข
1 Parent(s): 2c0eed0

First version

Browse files
Files changed (2) hide show
  1. app.py +22 -14
  2. 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
- def load_speakers(language, text):
37
- if text in list(default_text_dict.values()):
38
- newtext = default_text_dict[language]
39
- else:
40
- newtext = text
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('# MeloTTS Demo\n\nAn unofficial demo for [MeloTTS](https://github.com/myshell-ai/MeloTTS). **Make sure to try out several speakers, for example EN-Default!**')
44
  with gr.Group():
45
- speaker = gr.Dropdown(speaker_ids.keys(), interactive=True, value='EN-US', label='Speaker')
46
- language = gr.Radio(['EN', 'ES', 'FR', 'ZH', 'JP', 'KR'], label='Language', value='EN')
47
  speed = gr.Slider(label='Speed', minimum=0.1, maximum=10.0, value=1.0, interactive=True, step=0.1)
48
- text = gr.Textbox(label="Text to speak", value=default_text_dict['EN'])
49
- language.input(load_speakers, inputs=[language, text], outputs=[speaker, text])
50
- btn = gr.Button('Synthesize', variant='primary')
 
 
51
  aud = gr.Audio(interactive=False)
 
52
  btn.click(synthesize, inputs=[text, speaker, speed, language], outputs=[aud])
53
- gr.Markdown('Demo by [mrfakename](https://twitter.com/realmrfakename).')
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