-
Notifications
You must be signed in to change notification settings - Fork 5
/
TTS_MacAndLinux.php
63 lines (50 loc) · 1.58 KB
/
TTS_MacAndLinux.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
60
61
62
63
<?php
/*
_ _____ _ _ _ ___ __
| | |_ _| \ | | | | \ \ / /
| | | | | \| | | | |\ V /
| | | | | . ` | | | | > <
| |____ _| |_| |\ | |__| |/ . \
|______|_____|_| \_|\____//_/ \_\
*/
// Install eSpeak - Run this command in a terminal
/*
sudo apt-get install eSpeak
*/
/*
__ __ _____
| \/ | /\ / ____|
| \ / | / \ | |
| |\/| | / /\ \| |
| | | |/ ____ \ |____
|_| |_/_/ \_\_____|
*/
// Mac has it's own Speech Synthesis system
// accessible via the "say" command.
// To use eSpeak on a Mac, change this variable to true.
$mac_use_espeak = false;
// To use eSpeak on a Mac you need to install
// Homebrew Package Manager & eSpeak
// Run these commands in a terminal:
/*
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install espeak
*/
$voice = "espeak";
$statement = 'Hello World!';
$save_file_args = '-w HelloWorld.wav'; // eSpeak args
// Ask PHP what OS it was compiled for,
// CAPITALIZE it and truncate to the first 3 chars.
$OS = strtoupper(substr(PHP_OS, 0, 3));
// If this is Darwin (MacOS) AND we don't want eSpeak
elseif($OS === 'DAR' && $mac_use_espeak == false) {
$voice = "say -v 'Victoria'";
// Note: Mac say may require 4 char .wave extension
// if you receive an error about format try
// changing this to HelloWorld.wave
$save_file_args = '-o HelloWorld.wav'; // say args
}
// Say It
exec("$voice '$statement'");
// Save it to a File
exec("$voice '$statement' $save_file_args");