|
| 1 | +# Document to Audio Converter |
| 2 | + |
| 3 | +A simple Python utility to convert text from Microsoft Word (`.docx`) documents into spoken audio. You can either listen to the audio directly or save it as a `.wav` file. |
| 4 | + |
| 5 | +This script uses a simple, dialog-based interface for file selection and options. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Reads text content from `.docx` files. |
| 10 | +- Converts the extracted text into speech. |
| 11 | +- **Option 1:** Speak the text aloud, paragraph by paragraph. |
| 12 | +- **Option 2:** Save the entire text as a single `.wav` audio file. |
| 13 | +- Handles missing dependencies and file-opening errors gracefully. |
| 14 | + |
| 15 | +## Requirements |
| 16 | + |
| 17 | +- Python 3.x |
| 18 | +- The following Python libraries: |
| 19 | + - `pyttsx3` |
| 20 | + - `python-docx` |
| 21 | + - `pypiwin32` (often required by `pyttsx3` on Windows) |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +1. Clone this repository or download the `Pdftoaudio.py` script. |
| 26 | + |
| 27 | +2. Install the required libraries using pip: |
| 28 | + |
| 29 | + ```bash |
| 30 | + pip install pyttsx3 python-docx pypiwin32 |
| 31 | + ``` |
| 32 | + |
| 33 | +## How to Use |
| 34 | + |
| 35 | +1. Run the script from your terminal: |
| 36 | + |
| 37 | + ```bash |
| 38 | + python Pdftoaudio.py |
| 39 | + ``` |
| 40 | + |
| 41 | +2. A file dialog will open. Select the `.docx` document you want to convert. |
| 42 | + |
| 43 | +3. A dialog box will ask if you want to save the audio to a file. |
| 44 | + - Click **"Yes"** to open a "Save As" dialog and save the output as a `.wav` file. |
| 45 | + - Click **"No"** to have the script speak the document's text aloud directly. |
| 46 | +
|
| 47 | +4. Follow the on-screen prompts. Status messages will be printed to the console. |
| 48 | +
|
| 49 | +## Recent Code Improvements |
| 50 | +
|
| 51 | +The script was recently refactored to improve its quality, robustness, and maintainability. Key improvements include: |
| 52 | +
|
| 53 | +- **Dependency Management:** Imports are now organized at the top of the file. A startup check was added to ensure the `python-docx` library is installed, providing a user-friendly error message if it's missing. |
| 54 | +- **Robustness:** |
| 55 | + - The `tkinter` root window is now managed with a `contextmanager`, ensuring it is always properly destroyed. |
| 56 | + - A `try...finally` block was added around the text-to-speech engine logic to guarantee that `engine.stop()` is called, preventing the engine from hanging in case of an error. |
| 57 | +- **Code Structure & Readability:** |
| 58 | + - The `pyttsx3` engine setup was moved into its own helper function (`_initialize_engine`) to keep the main logic clean. |
| 59 | + - Type hints and docstrings were added to all functions, making the code self-documenting and easier to understand. |
| 60 | +
|
| 61 | +## Future Roadmap |
| 62 | +
|
| 63 | +This project is a great starting point, and there are several exciting features planned for the future to make it more powerful and user-friendly. |
| 64 | +
|
| 65 | +- **Support for More File Formats:** |
| 66 | + - Add support for reading text from **PDF files** (`.pdf`). |
| 67 | + - Add support for plain text files (`.txt`). |
| 68 | +
|
| 69 | +- **Full Graphical User Interface (GUI):** |
| 70 | + - Move away from simple dialog boxes to a complete GUI built with a framework like `tkinter` or `PyQt`. |
| 71 | + - The GUI would include features like a progress bar, play/pause/stop controls for live playback, and status displays. |
| 72 | +
|
| 73 | +- **Enhanced Audio Controls:** |
| 74 | + - Allow the user to select from available system voices. |
| 75 | + - Provide a slider or input box to adjust the speech rate and volume directly from the UI. |
| 76 | +
|
| 77 | +- **Cross-Platform Compatibility:** |
| 78 | + - Test and ensure the script works seamlessly on macOS and Linux. This may involve handling different text-to-speech engine backends. |
| 79 | +
|
| 80 | +- **Application Packaging:** |
| 81 | + - Package the application as a standalone executable (e.g., using `PyInstaller`) so that users can run it without needing to have Python or any libraries installed. |
| 82 | +
|
| 83 | +## Contributing |
| 84 | +
|
| 85 | +Contributions are welcome! If you'd like to help with any of the features on the roadmap or fix a bug, please feel free to fork the repository and submit a pull request. |
| 86 | +
|
| 87 | +## License |
| 88 | +
|
| 89 | +This project is licensed under the MIT License. See the `LICENSE` file for details. |
0 commit comments