Arjooohn commited on
Commit
2c32f32
·
verified ·
1 Parent(s): 352fca9
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -4,7 +4,8 @@ import numpy as np
4
  from PIL import Image
5
  import pytesseract
6
  from gtts import gTTS
7
- import io
 
8
 
9
  def preprocess(image):
10
  img = np.array(image)
@@ -30,11 +31,10 @@ def extract_text_and_speak(image):
30
 
31
  # Create TTS only if text exists
32
  if text and text != "No readable text found.":
33
- tts = gTTS(text)
34
- buffer = io.BytesIO()
35
- tts.write_to_fp(buffer)
36
- buffer.seek(0)
37
- audio_file = buffer
38
  else:
39
  audio_file = None
40
  if not text:
 
4
  from PIL import Image
5
  import pytesseract
6
  from gtts import gTTS
7
+ import tempfile
8
+ import os
9
 
10
  def preprocess(image):
11
  img = np.array(image)
 
31
 
32
  # Create TTS only if text exists
33
  if text and text != "No readable text found.":
34
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmpfile:
35
+ tts = gTTS(text)
36
+ tts.save(tmpfile.name)
37
+ audio_file = tmpfile.name
 
38
  else:
39
  audio_file = None
40
  if not text: