I want to write a game using pygame that is able to produce text-to-speech output.
I found the package pyttsx3
, which works fine on its own, e.g. like this:
import pyttsx3
engine = pyttsx3.init()
engine.say("abc")
engine.runAndWait()
pygame
on its own works fine as well, including audio. However, I can't get pyttsx3
to work together with pygame
:
import pygame
import pyttsx3
pygame.init()
engine = pyttsx3.init()
engine.say("abc")
engine.runAndWait()
When I run the script, I get no audio, but the following text output:
$ python example.py
pygame 2.1.0 (SDL 2.0.16, Python 3.9.7)
Hello from the pygame community. https://www.pygame.org/contribute.html
ALSA lib pcm_dmix.c:1035:(snd_pcm_dmix_open) unable to open slave
aplay: main:831: audio open error: Device or resource busy
This behaviour is independent of the import or init sequence. I'm running Arch Linux.