-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.php
59 lines (53 loc) · 1.85 KB
/
script.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
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
<?php
if(isset($_POST["data"][1])) {
$data = strtolower($_POST["data"][0] . " " . $_POST["data"][1]);
} else {
$data = strtolower($_POST["data"][0]);
}
echo $data;
//Write there you question and responge function
//For example "turn;off;light"=>"light_off"
//Replace spaces with ";"
//Don't forget to add comma if next line is next varriable :)
$arr = [
"turn;off;light"=>"off_light",
"turn;on;light"=>"on_light"
];
function callBack($word) {
switch($word) {
case "off_light"://This will be called by "Turn off light"
say("en", "Turning light off");//Define language and text to speech as responge
//Some next command
break;
case "on_light":
say("en", "Turning light on");
break;
}
}
//This is testing if spooken word defined in callBack words
foreach($arr as $word=>$w) {
if(str_contains($word, ";")) {
//Multiple words
$isExist = true;
foreach(explode(";", $word) as $words) {
if($data != $words && !str_contains($data, $words)) {
$isExist = false;
}
}
if($isExist) {
callBack($w);
}
} else {
//Single word
if($data == $word || str_contains($data, $word)) {
callBack($w);
}
}
}
//This function will generate mp3 file with responge by python gTTS
//and start PlaySound.exe made in C#, first argument is path to sound
function say($language, $text) {
shell_exec('py speech.py ' . $language . ' "' . $text . '"');
exec('start PlaySound.exe "C:/xampp/htdocs/rp.mp3"');
}
?>