root/trunk/plagger/lib/Plagger/Plugin/Publish/Speech/MacOSX.pm

Revision 521 (checked in by miyagawa, 3 years ago)

fix POD NAME header

Line 
1 package Plagger::Plugin::Publish::Speech::MacOSX;
2 use base qw( Plagger::Plugin::Publish::Speech );
3
4 use strict;
5 use DirHandle;
6 use Mac::Files;
7 use Mac::Speech;
8
9 sub feed {
10     my ($self, $context, $args) = @_;
11
12 #    unless( $self->is_ascii( $args->{feed}->title_text ) ){
13 #        Plagger->context->log(info => "Skip 2byte-included feed: " . $args->{feed}->title_text);
14 #        return;
15 #    }
16
17     my $voice = $self->conf->{voice} || 'Vicki';
18     if( $self->voice_validate( $voice ) ){
19         Plagger->context->log(debug => "$voice is ready to speak.");
20     }
21     else{
22         Plagger->context->log(info => "Voice '$voice' not found, will be replaced to 'Vicki'.");
23         $voice = 'Vicki';
24     }
25
26     my $speed;
27     if( $self->conf->{speed} =~ /^\d+(\.\d+)*$/o ){
28         $speed = $self->conf->{speed};
29         $speed = 4.0
30             if $speed > 4.0;
31         Plagger->context->log(debug => "Speed will be multiplied by $speed.")
32             if $speed != 1.0;
33     }
34
35     my $pitch;
36     if( $self->conf->{pitch} =~ /^\d+(\.\d+)*$/o ){
37         $pitch = $self->conf->{pitch};
38         $pitch = 2.0
39             if $pitch > 2.0;
40         Plagger->context->log(debug => "Pitch will be multiplied by $pitch.")
41             if $pitch != 1.0;
42     }
43
44     $self->speak( $voice, $speed, $pitch, $args->{feed}->title_text );
45
46     for my $entry ($args->{feed}->entries) {
47         my $stuff = $entry->title_text . ' ' . $entry->body_text;
48
49 #        unless( $self->is_ascii( $stuff ) ){
50 #            Plagger->context->log(info => "Can't speak 2byte-included entry, sorry.");
51 #            next;
52 #        }
53
54         $self->speak( $voice, $speed, $pitch, $stuff );
55     }
56 }
57
58 sub voice_validate {
59     my ($self, $voice) = @_;
60
61     if( my $d = DirHandle->new( FindFolder(kOnSystemDisk, kVoicesFolderType) ) ){
62         while( defined ($_ = $d->read) ){
63             return 1
64                 if /^$voice\.SpeechVoice$/i;
65         }
66     }
67 }
68
69 sub is_ascii {
70     my ($self, $str) = @_;
71
72     return $str =~ /[^\x00-\x7f]/o ? 0 : 1;
73 }
74
75 sub speak {
76     my ($self, $voice, $speed, $pitch, $message) = @_;
77
78     if( my $v = $Mac::Speech::Voice{ $voice } ){
79         my $channel = Mac::Speech::NewSpeechChannel( $v );
80
81         SetSpeechRate( $channel, GetSpeechRate( $channel ) * $speed )
82             if $speed;
83
84         SetSpeechPitch( $channel, GetSpeechPitch( $channel ) * $pitch )
85             if $pitch;
86
87         SpeakText( $channel => $message );
88         sleep 1
89             while SpeechBusy;
90
91         DisposeSpeechChannel( $channel );
92     }
93     else{
94         Plagger->context->log(error => "Voice sound file for '$voice' not found on your machine.");
95         return;
96     }
97 }
98
99 sub finalize { }
100
101 1;
102
103 __END__
104
105 =head1 NAME
106
107 Plagger::Plugin::Publish::Speech::MacOSX - speak your subscription on MacOSX
108
109 =head1 SYNOPSIS
110
111   - module: Publish::Speech
112     config:
113       voice: Vicki
114       speed: 0.96
115       pitch: 1.05
116
117 =head1 DESCRIPTION
118
119 Your Mac now speaks your subscriptions.
120
121 =head1 Config
122
123 =head2 voice
124
125 Following voices are available on MacOSX 10.4.
126
127  Agnes
128  Albert
129  BadNews
130  Bahh
131  Bells
132  Boing
133  Bruce
134  Bubbles
135  Cellos
136  Deranged
137  Fred
138  GoodNews
139  Hysterical
140  Junior
141  Kathy
142  Organ
143  Princess
144  Ralph
145  Trinoids
146  Vicki
147  Victoria
148  Whisper
149  Zarvox
150
151 =head2 speed
152
153 You can control the speed with setting multiplication factor (0.0 to 4.0).
154
155 =head2 pitch
156
157 You can control the sound pitch with setting multiplication factor (0.0 to 2.0).
158
159 =head1 CAVEATS
160
161 Only ascii feeds are available for speech.
162
163 =head1 AUTHOR
164
165 Ryo Okamoto <ryo@aquahill.net>
166
167 Based on the plugin Plagger::Plugin::Speech::Win32 by Tatsuhiko Miyagawa
168
169 =head1 SEE ALSO
170
171 L<Plagger>, L<Mac::Speech>
172
173 http://www.apple.com/education/accessibility/technology/text_to_speech.html
174
175 =cut
176
Note: See TracBrowser for help on using the browser.