-
Notifications
You must be signed in to change notification settings - Fork 23
/
run.php
43 lines (25 loc) · 964 Bytes
/
run.php
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
<?php
const kCFStringEncodingUTF8 = 0x08000100;
$speech = FFI::load('speech.h');
// Text to speech. One phrase per line.
$text = <<<EOT
Olá, eu sou a assistente virtual do Bob.
Sejam bem-vindos a palestra sobre F F I.
E sim, esse texto está sendo sintetizado pela biblioteca nativa do Mac, conversando direto com o P H P através do F F I.
Com vocês, o rei da gambiarra, Boooooob.
É nóis que voa bruxão!
EOT;
// Create a speech channel
$speechChannel = $speech->new('SpeechChannel', false);
$speech->NewSpeechChannel(null, FFI::addr($speechChannel));
$phrases = explode(PHP_EOL, $text);
foreach ($phrases as $phrase) {
// Transform the C String into CF String (Mac format)
$string = $speech->CFStringCreateWithCString(null, $phrase, kCFStringEncodingUTF8);
// Speak
$speech->SpeakCFString($speechChannel, $string, null);
while ($speech->SpeechBusy()) {
// Waits speech finish
}
echo $phrase . PHP_EOL;
}