-2

I want to make animated talking character using pygame and python text to speech pyttsx module. Below is my code I am figuring out how can I achieve this.

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();   
Swapnil Deo
  • 241
  • 1
  • 3
  • 16
  • What problem is it you're facing? What is it that doesn't work? Also, could you fix the indention in your code to match your existing code? Also, a couple of quick tips: 1. You don't need to use semicolon in Python. 2. Python has a proper boolean. `'false'` is a string while `False` (without quotation marks) is a boolean. – Ted Klein Bergman Jul 09 '18 at 13:03
  • i want to match lip sync with each word – Swapnil Deo Jul 09 '18 at 13:31

1 Answers1

1

Finally I resolved by multi threading concept in python. I referred the example mentioned here https://www.geeksforgeeks.org/multithreading-python-set-1/

I created 2 threads one to run animation and other to run engine.runAndWait();

Swapnil Deo
  • 241
  • 1
  • 3
  • 16