我想使用 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();