Added text along with the speak command. Updated window size.

This commit is contained in:
Storm Dragon 2024-07-22 16:08:42 -04:00
parent df386cbbd9
commit 9a6d6374f9

View File

@ -15,6 +15,7 @@ import pyperclip
import random import random
import re import re
import requests import requests
import textwrap
import webbrowser import webbrowser
# Global variable for speech provider # Global variable for speech provider
try: try:
@ -114,15 +115,33 @@ def read_config(readGlobal = False):
globalConfig.read_file(configfile) globalConfig.read_file(configfile)
except: except:
pass pass
def speak(text, interupt = True): def speak(text, interupt=True):
if speechProvider == "speechd": if speechProvider == "speechd":
if interupt == True: spd.cancel() if interupt: spd.cancel()
spd.say(text) spd.say(text)
else: else:
if speechProvider == "accessible_output2": if speechProvider == "accessible_output2":
s.speak(text, interrupt=True) s.speak(text, interrupt=True)
# Display the text on screen
screen = pygame.display.get_surface()
font = pygame.font.Font(None, 36)
# Wrap the text
maxWidth = screen.get_width() - 40 # Leave a 20-pixel margin on each side
wrappedText = textwrap.wrap(text, width=maxWidth // font.size('A')[0])
# Render each line
textSurfaces = [font.render(line, True, (255, 255, 255)) for line in wrappedText]
screen.fill((0, 0, 0)) # Clear screen with black
# Calculate total height of text block
totalHeight = sum(surface.get_height() for surface in textSurfaces)
# Start y-position (centered vertically)
currentY = (screen.get_height() - totalHeight) // 2
# Blit each line of text
for surface in textSurfaces:
textRect = surface.get_rect(center=(screen.get_width() // 2, currentY + surface.get_height() // 2))
screen.blit(surface, textRect)
currentY += surface.get_height()
pygame.display.flip()
def check_for_exit(): def check_for_exit():
for event in pygame.event.get(): for event in pygame.event.get():
@ -153,7 +172,7 @@ def initialize_gui(gameTitle):
# start pygame # start pygame
pygame.init() pygame.init()
# start the display (required by the event loop) # start the display (required by the event loop)
pygame.display.set_mode((320, 200)) pygame.display.set_mode((800, 600))
pygame.display.set_caption(gameTitle) pygame.display.set_caption(gameTitle)
# Set 32 channels for sound by default # Set 32 channels for sound by default
pygame.mixer.pre_init(44100, -16, 2, 1024) pygame.mixer.pre_init(44100, -16, 2, 1024)