Created
October 13, 2022 14:48
-
-
Save MarioRuiz/fda66e2bacab59432cac4bd66150434e to your computer and use it in GitHub Desktop.
Learn to write Spanish and English words. Aprende a escribir palabras en Inglés y Español
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires an Apple Mac and Ruby | |
# I created this gist just to help my daughter to learn how words are written in Spanish and English. | |
# The script will pronounce a random word in the language selected and the child needs to write the word letter by letter. | |
require 'string_pattern' | |
require 'open3' | |
require 'io/console' | |
ENV['NOMBRE'] ||= 'Pedro' | |
ENGLISH = ENV['ENGLISH'] == 'true' | |
MAYUSCULAS = ENV['MAYUSCULAS'] == 'true' | |
RAND = ENV['RAND'] != 'false' | |
ACENTOS = ENV['ACENTOS'] == 'true' | |
if ENGLISH | |
PALABRAS = "Daddy, Mommy, house, hug, table, food, chair, car, glass, kiss, dish, door, baby, Mario, pictures, pasta, bed, robot, | |
computer, screens, milk, water, apple, wolf, sleepy, dream, sleep, trees, sea, man, woman, princess, king, prince, queen, coat" | |
else | |
PALABRAS = "Papá, Mamá, casa, abrazo, mesa, comida, silla, coche, vaso, beso, plato, puerta, nene, nena, Mario, Ruiz, fotos, pasta, cama, robot, | |
pantallas, ordenador, leche, agua, manzana, lobo, sueño, dormir, árboles, mar, hombre, mujer, princesa, reina, rey, abrigo" | |
end | |
def di(txt,printit=true) | |
puts "\n" | |
ENGLISH ? voice = 'Samantha': voice = 'Monica' | |
stdin, stdout, stderr, wait_thr = Open3.popen3("say -v #{voice} \"#{txt}\" ") | |
txt.upcase! if MAYUSCULAS | |
unless ACENTOS | |
txt = txt.gsub('á','a').gsub('é','e').gsub('í','i').gsub('ó','o').gsub('ú','u') | |
txt = txt.gsub('Á','A').gsub('É','E').gsub('Í','I').gsub('Ó','O').gsub('Ú','U') | |
end | |
txt.each_char do |ch| | |
sleep (rand*0.1) | |
print ch if printit | |
end | |
puts "\n" | |
while wait_thr.status == 'run' or wait_thr.status == 'sleep' | |
sleep 0.2 | |
end | |
end | |
def pregunta(txt, una=false) | |
print "> " | |
if una | |
print txt | |
di txt[-1], false | |
resp = STDIN.getch | |
else | |
di txt | |
resp = gets.upcase.chop | |
end | |
resp.upcase! | |
resp = resp.gsub('Á','A').gsub('É','E').gsub('Í','I').gsub('Ó','O').gsub('Ú','U') unless ACENTOS | |
return resp | |
end | |
if ENGLISH | |
di "Hi #{ENV['NOMBRE']}!. I'm Lola" | |
di "Your robot teacher." | |
di "Let's play" | |
else | |
di "Hola #{ENV['NOMBRE']}!. Soy Lola" | |
di "Tu maestra robot." | |
di "Vamos a jugar" | |
end | |
resp = '' | |
while resp!='SI' and resp!='SÍ' and resp!='NO' and resp!='YES' do | |
if ENGLISH | |
resp = pregunta("Do you want to play?") | |
else | |
resp = pregunta("¿Quieres jugar un ratito?") | |
end | |
if resp == "SI" or resp == 'SÍ' or resp == 'YES' | |
if ENGLISH | |
di "Perfect, so let's learn to write some words" | |
else | |
di "Perfecto, pues vamos a aprender a escribir algunas palabras" | |
end | |
while true | |
if RAND | |
if ENGLISH | |
palabra = "1-15:w&".gen | |
else | |
palabra = "1-15:p&".gen | |
end | |
else | |
palabra = PALABRAS.split(", ").sample | |
end | |
palabra.upcase! if MAYUSCULAS | |
if ENGLISH | |
di "Let's see how to write the word, #{palabra}" | |
else | |
di "Vamos a ver cómo se escribe la palabra, #{palabra}" | |
end | |
palabra_tmp = '' | |
palabra.each_char do |ch| | |
correcto = false | |
while !correcto | |
palabra_tmp+=ch | |
resp = pregunta(palabra_tmp, true) | |
if resp == ch.upcase | |
correcto = true | |
else | |
palabra_tmp.chop! | |
if ENGLISH | |
di "Try again, that was, #{resp}" | |
else | |
di "Prueba otra vez, eso era una, #{resp}" | |
end | |
end | |
end | |
end | |
di palabra | |
if ENGLISH | |
di "Well done" | |
else | |
di "Muy bien" | |
end | |
end | |
elsif resp == 'NO' | |
if ENGLISH | |
di "See you soon" | |
di "Bye bye" | |
else | |
di "Nos vemos pronto" | |
di "Adiós. Chao chao" | |
end | |
else | |
if ENGLISH | |
di "I didn't understand you, you can answer, Yes or No" | |
else | |
di "No he entendido, puedes responder, Sí o No" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment