-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow.py
86 lines (58 loc) · 2.11 KB
/
show.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pygame
import time
def show_init(): # initialize pygame variables like screeen
pygame.init()
screen_size=(1500, 600)
screen=pygame.display.set_mode(screen_size)
pygame.display.set_caption('Show speech')
return screen
def paint(screen, txt, posx, posy): # function to show converted speech
green = (0, 255, 0)
font = pygame.font.Font('freesansbold.ttf', 18)
screen.fill((0, 0, 0), rect=[posx, posy, (font.size(txt[0])[0]*100), 20])
clock = pygame.time.Clock()
text = font.render(txt, True, green)
# create a rectangular object for the text surface object
textRect = text.get_rect()
if((posx + textRect[2]) <= 800):
textRect = textRect.move(posx, posy)
else:
posy +=textRect[3]
posx = 0
textRect = textRect.move(posx, posy)
#posx += textRect[2]
pygame.display.update()
for i in range(len(txt)):
text2 = font.render(txt[i], True, green)
screen.blit(text2, (posx +(font.size(txt[:i])[0]), posy))
pygame.display.update()
clock.tick(12)
posx += textRect[2]
return pygame.display.get_surface(), posx, posy
def pred_show(screen, txt, posx, posy): # function to show predicted speech
green = (0, 255, 0)
blue = (0, 0, 128)
font = pygame.font.Font('freesansbold.ttf', 18)
text = font.render(txt, True, green, blue)
# create a rectangular object for the text surface object
textRect = text.get_rect()
if((posx + textRect[2]) <= 800):
print(str(posx+textRect[2])+ "ii")
textRect = textRect.move(posx, posy)
else:
print(str(textRect[3]+ posy) + "jj")
textRect = textRect.move(0, 300)
#posx += textRect[2]
pygame.display.update()
# infinite loop
screen.blit(text, (posx, posy))
pygame.display.update()
return pygame.display.get_surface()
'''
screen = show_init()
posx = 0
posy = 0
for i in range(7):
print(str(posx)+ " " + str(posy))
text = "My name is shaashwat and i am awesome" + str(i)
posx, posy = paint(screen, text, posx, posy)'''