'Playing an MP3 file using Python
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")
Solution 1:[1]
You can try the playsound
module
from playsound import playsound
playsound("audio_file.mp3")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | none none |