-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTTS_Windows.php
115 lines (95 loc) · 3.18 KB
/
TTS_Windows.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
// List available SAPI voices
// 0 = Microsoft David Desktop - English (United States)
// 1 = Microsoft Zira Desktop - English (United States)
// ... If you have additional voices installed
function ListSAPIVoices(&$voice){
foreach($voice->GetVoices as $v){
echo $v->GetDescription . PHP_EOL;
}
}
$filename = "DaisyBell.wav";
// https://en.wikipedia.org/wiki/Daisy_Bell#Computing_and_technology
// "In 1961, an IBM 704 at Bell Labs was programmed to sing "Daisy Bell"-
// in the earliest demonstration of computer speech synthesis."
$statement = "There is a flower within my heart, Daisy, Daisy!
Planted one day by a glancing dart,
Planted by Daisy Bell!
Whether she loves me or loves me not,
Sometimes it's hard to tell;
Yet I am longing to share the lot
Of beautiful Daisy Bell!
Daisy, Daisy,
Give me your answer, do!
I'm half crazy,
All for the love of you!
It won't be a stylish marriage,
I can't afford a carriage,
But you'll look sweet on the seat
Of a bicycle built for two!
We will go tandem as man and wife, Daisy, Daisy!
Ped'ling away down the road of life, I and my Daisy Bell!
When the road's dark we can both despise Po'leaseman and lamps as well;
There are bright lights in the dazzling eyes Of beautiful Daisy Bell!
Daisy, Daisy,
Give me your answer, do!
I'm half crazy,
All for the love of you!
It won't be a stylish marriage,
I can't afford a carriage,
But you'll look sweet on the seat
Of a bicycle built for two!
I will stand by you in wheel or woe, Daisy, Daisy!
You'll be the bell which I'll ring you know! Sweet little Daisy Bell!
You'll take the lead in each trip we take, Then if I don't do well;
I will permit you to use the brake, My beautiful Daisy Bell!";
// COM (Component Object Model) objects
// https://www.php.net/manual/en/book.com.php
$voice = new COM("SAPI.SpVoice");
$voice_file_stream = new COM("SAPI.SpVoice");
$file_stream = new COM("SAPI.SpFileStream");
// Change $voice to Zira
$voice->Voice = $voice->GetVoices()->Item(1);
// Change $voice_file_stream to David
$voice_file_stream->Voice = $voice_file_stream->GetVoices()->Item(0);
// Have voices announce themselves
//$voice->Speak($voice->Voice->GetDescription); // (Zira)
//$voice_file_stream->Speak($voice_file_stream->Voice->GetDescription); // (David)
/*
Select Stream Quality:
11kHz 8Bit Mono = 8
11kHz 8Bit Stereo = 9
11kHz 16Bit Mono = 10
11kHz 16Bit Stereo = 11
...
16kHz 8Bit Mono = 16
16kHz 8Bit Stereo = 17
16kHz 16Bit Mono = 18;
16kHz 16Bit Stereo = 19
...
32kHz 8Bit Mono = 28
32kHz 8Bit Stereo = 29
32kHz 16Bit Mono = 30
32kHz 16Bit Stereo = 31
...
*/
// Set stream quality
$file_stream->Format->Type = 17; // 16kHz 8Bit Stereo
/*
Select Speech StreamFile Mode:
Read = 0
ReadWrite = 1
Create = 2
CreateForWrite = 3
*/
$mode = 3;
// Have $voice (Zira) announce beginning file stream
$voice->Speak('Opening audio file stream');
// Output TTS to File
$file_stream->Open($filename, $mode); // Open stream and create file
$voice_file_stream->AudioOutputStream = $file_stream; // Begin streaming TTS
// Have $voice_file_stream (David) speak $statement
$voice_file_stream->Speak($statement);
$file_stream->Close; // Close stream
// Have $voice (Zira) announce file stream completion
$voice->Speak('File stream complete');