├── .python-version ├── main.png ├── requirements.txt ├── .vscode └── settings.json ├── README.md └── main.py /.python-version: -------------------------------------------------------------------------------- 1 | 2 | grad 3 | -------------------------------------------------------------------------------- /main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salma71/text_speech/HEAD/main.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | 2 | gradio 3 | gTTS==2.2.1 4 | pdfminer.six==20201018 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.fontSize": 16, 3 | "python.pythonPath": "./venv/bin/python" 4 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Text to Speech using Gradio 2 | 3 | ![Main image](main.png) 4 | 5 | Convert pdf files into spoken audio using google text to speech package and building a user-friendly ready-made interface using [Gradio package](https://www.gradio.app/). 6 | 7 | ## Installation 8 | 9 | Fork or clone the repo and run 10 | 11 | ```bash 12 | pip install -rrequirements.txt 13 | ``` 14 | 15 | ## Usage 16 | 17 | Follow a step-by-step guide tutorial in that Medium article! 18 | 19 | ``` 20 | 21 | ## Contributing 22 | 23 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 24 | 25 | Please make sure to update tests as appropriate. 26 | 27 | ## License 28 | 29 | [MIT](https://choosealicense.com/licenses/mit/) 30 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from gtts import gTTS 2 | from pdfminer.high_level import extract_text 3 | import gradio as gr 4 | import os 5 | 6 | 7 | def pdf_to_text(file_obj): 8 | text = extract_text(file_obj.name) 9 | myobj = gTTS(text=text, lang='en', slow=False) 10 | myobj.save("test.wav") 11 | return 'test.wav' 12 | 13 | 14 | examples = [ 15 | [os.path.abspath("short-pdf.pdf")], 16 | [os.path.abspath("long-pdf.pdf")] 17 | ] 18 | 19 | 20 | iface = gr.Interface(fn = pdf_to_text, 21 | inputs = 'file', 22 | outputs = 'audio', 23 | verbose = True, 24 | title = 'PDF to Audio Application', 25 | description = 'A simple application to convert PDF files in audio speech. Upload your own file, or click one of the examples to load them.', 26 | article = 27 | '''
28 |

All you need to do is to upload the pdf file and hit submit, then wait for compiling. After that click on Play/Pause for listing to the audio. The audio is saved in a wav format.

29 |
''', 30 | examples=examples 31 | ) 32 | 33 | iface.launch() 34 | --------------------------------------------------------------------------------