Skip to content

Instantly share code, notes, and snippets.

@rafaelfreba
Forked from danilowm/gist:1997944
Last active May 19, 2022 17:28
Show Gist options
  • Save rafaelfreba/a0902af287f508354aa895e1adfa22ce to your computer and use it in GitHub Desktop.
Save rafaelfreba/a0902af287f508354aa895e1adfa22ce to your computer and use it in GitHub Desktop.
Função de Saudação Falada (bom dia, boa tarde e boa noite)
<?php
function saudacaoFalada($nome = ''){
date_default_timezone_set('America/Cuiaba');
$hora = date('H');
if( $hora >= 6 && $hora <= 12 )
$saudacao = 'Bom dia' . (empty($nome) ? '!' : ', ' . $nome);
else if ($hora > 12 && $hora <= 18 )
$saudacao = 'Boa tarde' . (empty($nome) ? '!' : ', ' . $nome);
else
$saudacao = 'Boa noite' . (empty($nome) ? '!' : ', ' . $nome);
return "<script>speechSynthesis.speak(new SpeechSynthesisUtterance('$saudacao'));</script>";
}
echo saudacaoFalada( 'Danilo' );
// Irá falar conforme o horário:
// Bom dia Danilo!
?>
@rafaelfreba
Copy link
Author

Adicionei a opção de falar a saudação através da Web Speech API. (Funcionando no Edge e Firefox)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment