I'm generating a text-to-speech mp3 file using gTTS module. Then I store it on a buffer using BytesIO().
Here, mp3 = BytesIO(). When I try to set a file location using the .seek() function like mp3.seek(0) where 0 signifies the start of the buffer, it gives the following error -
ValueError: invalid whence (-1, should be 0, 1 or 2)
Traceback (most recent call last):
File "C:/Users/%SOME_PATH%/test_audio.py", line 17, in <module>
sayText("Hello World")
File "C:/Users/%SOME_PATH%/test_audio.py", line 14, in sayText
mixer.music.load(mp3)
pygame.error: ModPlug_Load failed
I don't know why it is calling it an invalid whence. The valid ones are 0, 1, 2, and I'm passing the value 0 and I don't see the point in changing it something else other than 0.
Here's the full code -
from gtts import gTTS
from io import BytesIO
from pygame import mixer
def sayText(tosaytext):
# Use gTTS to Store Speech on Buffer
tts = gTTS(text=tosaytext, lang='en-uk')
mp3 = BytesIO()
tts.write_to_fp(mp3)
mp3.seek(0)
# Play from Buffer
mixer.init()
mixer.music.load(mp3)
mixer.music.play()
sayText("Hello World")
Can anyone point out where I'm going wrong with any solution to it? Thank You!