[Python] How to make animated face speak using pygame and pyttsx

Discussão em 'Python' iniciado por Stack, Abril 27, 2025.

  1. Stack

    Stack Membro Participativo

    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();

    Continue reading...

Compartilhe esta Página