Text to Audio Bangla

from flask import Flask, render_template, request, send_file from docx import Document from gtts import gTTS import os app = Flask(__name__) UPLOAD_FOLDER = "uploads" OUTPUT_FOLDER = "output" os.makedirs(UPLOAD_FOLDER, exist_ok=True) os.makedirs(OUTPUT_FOLDER, exist_ok=True) def read_docx(file_path): """Reads text from a .docx file.""" if not os.path.exists(file_path): return None doc = Document(file_path) text = "\n".join([para.text.strip() for para in doc.paragraphs if para.text.strip()]) return text if text else None def text_to_audio(text, output_file): """Converts text to speech and saves it as an MP3 file.""" try: tts = gTTS(text=text, lang='bn', tld="com.bd") tts.save(output_file) except Exception as e: return str(e) return None @app.route('/', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': if 'file' not in request.files: return "No file part" file = request.files['file'] if file.filename == '': return "No selected file" if file: file_path = os.path.join(UPLOAD_FOLDER, file.filename) file.save(file_path) text = read_docx(file_path) if not text: return "Error: Document is empty!" audio_filename = file.filename.replace(".docx", ".mp3") audio_path = os.path.join(OUTPUT_FOLDER, audio_filename) error = text_to_audio(text, audio_path) if error: return f"Error in conversion: {error}" return send_file(audio_path, as_attachment=True) return ''' Docx to Audio Converter

Upload a Word file (.docx) to convert to audio

''' if __name__ == '__main__': app.run(debug=True)

Text to Audio Bangla

from flask import Flask, render_template, request, send_file from docx import Document from gtts import gTTS import os app = Flask(__name__...