我想使用pygame和python文本到语音pyttsx模块来制作动画说话人物。 以下是我正在寻找的代码,该如何实现。
import pygame,time
import sys,math
import pyttsx
from pygame import gfxdraw
PI = math.pi;
pygame.init()
screen = pygame.display.set_mode((640, 480))
back = (255,255,255);
color = (255,255,0);
mouth_flag = 'false';
engine = pyttsx.init()
engine.say('Good morning.')
while True:
time.sleep( 0.25 )
screen.fill(back);
pygame.gfxdraw.filled_circle(screen,320,240,100,color);
pygame.gfxdraw.filled_circle(screen,270,210,20,(0,0,0));
pygame.gfxdraw.filled_circle(screen,370,210,20,(0,0,0));
if mouth_flag=='false':
pygame.gfxdraw.arc(screen,320,240,75,25, 155, (0,0,0))
mouth_flag='true';
else:
pygame.gfxdraw.line(screen,270,290,370,290,(0,0,0));
mouth_flag='false';
pygame.display.update();
engine.runAndWait();
答案 0 :(得分:0)
最后,我通过python中的多线程概念解决了。我提到了例子 这里https://www.geeksforgeeks.org/multithreading-python-set-1/
我创建了2个线程,一个用于运行动画,另一个用于运行engine.runAndWait();