0

I'm working on a project to convert texts into audio as in the following code. It is working fine, but I want to play the MP3 file without opening media player. How can I do that?

The code:

import cv2
import pytesseract
from gtts import gTTS
import os

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
img = cv2.imread('1.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
X= pytesseract.image_to_string(img)
language = 'en'
myobj = gTTS(text=X, lang=language, slow=False)
myobj.save("welcome.mp3")
os.system("welcome.mp3")
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
johnx
  • 35
  • 1
  • 7

1 Answers1

0

You can try the playsound module

from playsound import playsound
playsound("audio_file.mp3")
none none
  • 191
  • 2
  • 14
  • i did but it gives me an erreo like this Error 259 for command: play welcome.mp3 wait The driver cannot recognize the specified command parameter. – johnx Apr 27 '22 at 10:36
  • citing [this post](https://stackoverflow.com/questions/68704443/python-playsound-error-261-for-command-the-driver-cannot-recognize-the-specifie): try uninstalling it and then installing a previous version (with `pip install playsound==1.2.2`). The latest version seems to have broken something in some systems – none none Apr 27 '22 at 11:02
  • Did the downgraded version work? – none none Apr 28 '22 at 08:21