line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NetStumbler::Speech;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
29183
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter;
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#
|
11
|
|
|
|
|
|
|
# We all for several exports
|
12
|
|
|
|
|
|
|
#
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01';
|
14
|
1
|
|
|
1
|
|
537
|
use Win32::OLE qw(in with);
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Win32::OLE::Const;
|
16
|
|
|
|
|
|
|
our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
|
17
|
|
|
|
|
|
|
#
|
18
|
|
|
|
|
|
|
# Exported Functions by request
|
19
|
|
|
|
|
|
|
#
|
20
|
|
|
|
|
|
|
@EXPORT_OK = qw(
|
21
|
|
|
|
|
|
|
hasLibrary
|
22
|
|
|
|
|
|
|
initializeSpeech
|
23
|
|
|
|
|
|
|
speak
|
24
|
|
|
|
|
|
|
setVoice
|
25
|
|
|
|
|
|
|
getVoices
|
26
|
|
|
|
|
|
|
getVoiceDesc
|
27
|
|
|
|
|
|
|
); # symbols to export on request
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 Object Methods
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 new()
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Returns a new Wap object. NOTE: this method may take some time to execute
|
34
|
|
|
|
|
|
|
as it loads the list into memory at construction time
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new
|
39
|
|
|
|
|
|
|
{
|
40
|
|
|
|
|
|
|
my $proto = shift;
|
41
|
|
|
|
|
|
|
my $class = ref($proto) || $proto;
|
42
|
|
|
|
|
|
|
my $self = {};
|
43
|
|
|
|
|
|
|
$Win32::OLE::Warn = 3; # die on errors...
|
44
|
|
|
|
|
|
|
$self->{hasSpeech} = 1;
|
45
|
|
|
|
|
|
|
$self->{speech} = undef;
|
46
|
|
|
|
|
|
|
$self->{initialized} = 0;
|
47
|
|
|
|
|
|
|
bless ($self, $class);
|
48
|
|
|
|
|
|
|
eval
|
49
|
|
|
|
|
|
|
{
|
50
|
|
|
|
|
|
|
use Win32::OLE::Const 'Microsoft Speech Object Library';
|
51
|
|
|
|
|
|
|
};
|
52
|
|
|
|
|
|
|
if($@)
|
53
|
|
|
|
|
|
|
{
|
54
|
|
|
|
|
|
|
$self->{hasSpeech} = 0;
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
return $self;
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 hasLibrary
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Params:
|
62
|
|
|
|
|
|
|
none
|
63
|
|
|
|
|
|
|
Returns:
|
64
|
|
|
|
|
|
|
true if speech library could be loaded
|
65
|
|
|
|
|
|
|
Example:
|
66
|
|
|
|
|
|
|
if($obj->hasLibrary)
|
67
|
|
|
|
|
|
|
{
|
68
|
|
|
|
|
|
|
# do something here
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub hasLibrary
|
75
|
|
|
|
|
|
|
{
|
76
|
|
|
|
|
|
|
my $self = shift;
|
77
|
|
|
|
|
|
|
return $self->{hasSpeech};
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 initializeSpeech
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Params:
|
83
|
|
|
|
|
|
|
none
|
84
|
|
|
|
|
|
|
Returns:
|
85
|
|
|
|
|
|
|
true if speech library could be initialized
|
86
|
|
|
|
|
|
|
Example:
|
87
|
|
|
|
|
|
|
if($obj->initializeSpeech)
|
88
|
|
|
|
|
|
|
{
|
89
|
|
|
|
|
|
|
# do something here
|
90
|
|
|
|
|
|
|
}
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub initializeSpeech
|
95
|
|
|
|
|
|
|
{
|
96
|
|
|
|
|
|
|
my $self = shift;
|
97
|
|
|
|
|
|
|
if($self->{hasSpeech})
|
98
|
|
|
|
|
|
|
{
|
99
|
|
|
|
|
|
|
$self->{speech} = Win32::OLE->new('Sapi.SpVoice');
|
100
|
|
|
|
|
|
|
$self->{initialized} = 1;
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
return $self->{initialized};
|
103
|
|
|
|
|
|
|
}
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 speak(string)
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Params:
|
108
|
|
|
|
|
|
|
-string The string to speak
|
109
|
|
|
|
|
|
|
Returns:
|
110
|
|
|
|
|
|
|
none
|
111
|
|
|
|
|
|
|
Example:
|
112
|
|
|
|
|
|
|
$obj->speak("Hello world");
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub speak
|
117
|
|
|
|
|
|
|
{
|
118
|
|
|
|
|
|
|
my $self = shift;
|
119
|
|
|
|
|
|
|
if($self->{hasSpeech})
|
120
|
|
|
|
|
|
|
{
|
121
|
|
|
|
|
|
|
unless($self->{initialized})
|
122
|
|
|
|
|
|
|
{
|
123
|
|
|
|
|
|
|
$self->initializeSpeech();
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
my $words = shift;
|
126
|
|
|
|
|
|
|
$self->{speech}->Speak($words,1);
|
127
|
|
|
|
|
|
|
}
|
128
|
|
|
|
|
|
|
}
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 setVoice(number)
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Params:
|
133
|
|
|
|
|
|
|
-number The voice number to use
|
134
|
|
|
|
|
|
|
Returns:
|
135
|
|
|
|
|
|
|
none
|
136
|
|
|
|
|
|
|
Example:
|
137
|
|
|
|
|
|
|
$obj->setVoice(1);
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub setVoice
|
142
|
|
|
|
|
|
|
{
|
143
|
|
|
|
|
|
|
my $self = shift;
|
144
|
|
|
|
|
|
|
if($self->{hasSpeech})
|
145
|
|
|
|
|
|
|
{
|
146
|
|
|
|
|
|
|
unless($self->{initialized})
|
147
|
|
|
|
|
|
|
{
|
148
|
|
|
|
|
|
|
$self->initializeSpeech();
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
my $voice = shift;
|
151
|
|
|
|
|
|
|
$self->{speech}->{Voice} = $self->{speech}->GetVoices()->Item($voice);
|
152
|
|
|
|
|
|
|
}
|
153
|
|
|
|
|
|
|
}
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 getVoiceDesc(number)
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Params:
|
158
|
|
|
|
|
|
|
-number The voice number you want to get the description for
|
159
|
|
|
|
|
|
|
Returns:
|
160
|
|
|
|
|
|
|
string description of the voice
|
161
|
|
|
|
|
|
|
Example:
|
162
|
|
|
|
|
|
|
print "Voice 1 ",$obj->getVoiceDesc(1),"\n";
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub getVoiceDesc
|
167
|
|
|
|
|
|
|
{
|
168
|
|
|
|
|
|
|
my $self = shift;
|
169
|
|
|
|
|
|
|
if($self->{hasSpeech})
|
170
|
|
|
|
|
|
|
{
|
171
|
|
|
|
|
|
|
unless($self->{initialized})
|
172
|
|
|
|
|
|
|
{
|
173
|
|
|
|
|
|
|
$self->initializeSpeech();
|
174
|
|
|
|
|
|
|
}
|
175
|
|
|
|
|
|
|
my $voice = shift;
|
176
|
|
|
|
|
|
|
return $self->{speech}->GetVoices()->Item($voice)->GetDescription();
|
177
|
|
|
|
|
|
|
}
|
178
|
|
|
|
|
|
|
}
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 getVoices()
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Params:
|
183
|
|
|
|
|
|
|
none
|
184
|
|
|
|
|
|
|
Returns:
|
185
|
|
|
|
|
|
|
hash of voices keyed by voice number
|
186
|
|
|
|
|
|
|
Example:
|
187
|
|
|
|
|
|
|
my %hash = $obj->getVoices;
|
188
|
|
|
|
|
|
|
foreach my $key (keys(%hash))
|
189
|
|
|
|
|
|
|
{
|
190
|
|
|
|
|
|
|
print "Voice $key ",$hash{$key};
|
191
|
|
|
|
|
|
|
}
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub getVoices
|
196
|
|
|
|
|
|
|
{
|
197
|
|
|
|
|
|
|
my $self = shift;
|
198
|
|
|
|
|
|
|
if($self->{hasSpeech})
|
199
|
|
|
|
|
|
|
{
|
200
|
|
|
|
|
|
|
unless($self->{initialized})
|
201
|
|
|
|
|
|
|
{
|
202
|
|
|
|
|
|
|
$self->initializeSpeech();
|
203
|
|
|
|
|
|
|
}
|
204
|
|
|
|
|
|
|
my $vg = $self->{speech}->GetVoices();
|
205
|
|
|
|
|
|
|
my $cnt = $vg->{Count};
|
206
|
|
|
|
|
|
|
my %voices;
|
207
|
|
|
|
|
|
|
for(my $i=0;$i<$cnt;$i++)
|
208
|
|
|
|
|
|
|
{
|
209
|
|
|
|
|
|
|
$voices{$i} = $vg->Item($i)->GetDescription();
|
210
|
|
|
|
|
|
|
}
|
211
|
|
|
|
|
|
|
return %voices;
|
212
|
|
|
|
|
|
|
}
|
213
|
|
|
|
|
|
|
}
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
1;
|
217
|
|
|
|
|
|
|
__END__
|