-3

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

1 回答 1

0

最后我通过python中的多线程概念解决了。我提到了这里提到的例子https://www.geeksforgeeks.org/multithreading-python-set-1/

我创建了 2 个线程,一个用于运行动画,另一个用于运行 engine.runAndWait();

于 2018-07-17T02:39:55.573 回答