macsay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +20 -0
  2. data/ext/extconf.rb +3 -0
  3. data/ext/macsay.c +57 -0
  4. data/ext/say.m +51 -0
  5. metadata +71 -0
data/README ADDED
@@ -0,0 +1,20 @@
1
+ = MacSay
2
+
3
+ Copyright (c) 2012 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
4
+
5
+ == Description
6
+
7
+ Simple Ruby bindings for NSSpeechSynthesizer.
8
+
9
+ == Example
10
+
11
+ require 'macsay'
12
+
13
+ voices = MacSay.available_voices
14
+ voice = voices.sort_by { rand }.first
15
+
16
+ # ゆっくりしていってね!!!
17
+ MacSay.say('yukkuri shite itte ne!!!', voice)
18
+
19
+ # ゆっくりしね!!!
20
+ MacSay.say('yukkuri shine!!!')
data/ext/extconf.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+ $LDFLAGS = ' -framework Cocoa '
3
+ create_makefile('macsay')
data/ext/macsay.c ADDED
@@ -0,0 +1,57 @@
1
+ #include <stddef.h>
2
+ #include "ruby.h"
3
+
4
+ void say(char *cmsg, char *voice);
5
+ void available_voices(void (*func)(void *, char *), void *data);
6
+
7
+ static VALUE rb_macsay_say(int argc, VALUE *argv, VALUE self) {
8
+ VALUE msg, voice;
9
+ char *cmsg, *cvoice;
10
+
11
+ rb_scan_args(argc, argv, "11", &msg, &voice);
12
+
13
+ Check_Type(msg, T_STRING);
14
+ cmsg = StringValuePtr(msg);
15
+
16
+ if (NIL_P(voice)) {
17
+ cvoice = NULL;
18
+ } else {
19
+ Check_Type(voice, T_STRING);
20
+ cvoice = StringValuePtr(voice);
21
+ }
22
+
23
+ if (RSTRING_LEN(msg) < 1) {
24
+ return Qnil;
25
+ }
26
+
27
+ say(cmsg, cvoice);
28
+
29
+ return Qnil;
30
+ }
31
+
32
+ void rb_macsay_available_voices0(void *data, char *cvoice) {
33
+ VALUE voices, voice;
34
+
35
+ voices = (VALUE) data;
36
+ voice = rb_str_new2(cvoice);
37
+ rb_ary_push(voices, voice);
38
+ }
39
+
40
+ static VALUE rb_macsay_available_voices(VALUE self) {
41
+ VALUE voices;
42
+
43
+ voices = rb_ary_new();
44
+
45
+ available_voices(rb_macsay_available_voices0, (void *) voices);
46
+
47
+ return voices;
48
+ }
49
+
50
+ void Init_macsay() {
51
+ VALUE rb_mMacSay;
52
+
53
+ rb_mMacSay = rb_define_module("MacSay");
54
+
55
+ rb_define_module_function(rb_mMacSay, "say", rb_macsay_say, -1);
56
+ rb_define_module_function(rb_mMacSay, "available_voices", rb_macsay_available_voices, 0);
57
+ }
data/ext/say.m ADDED
@@ -0,0 +1,51 @@
1
+ #include <unistd.h>
2
+ #import <Cocoa/Cocoa.h>
3
+
4
+ #define WAIT 0.1
5
+
6
+ void *say(char *cmsg, char *cvoice) {
7
+ NSAutoreleasePool *pool;
8
+ NSSpeechSynthesizer* speech;
9
+ NSString *voice, *msg;
10
+
11
+ pool = [[NSAutoreleasePool alloc] init];
12
+
13
+ msg = [NSString stringWithCString: cmsg encoding:NSUTF8StringEncoding];
14
+
15
+ if (cvoice) {
16
+ voice = [NSString stringWithCString: cvoice encoding:NSUTF8StringEncoding];
17
+ } else {
18
+ voice = [NSSpeechSynthesizer defaultVoice];
19
+ }
20
+
21
+ speech = [[NSSpeechSynthesizer alloc] initWithVoice:voice];
22
+
23
+ [speech startSpeakingString: msg];
24
+
25
+ while ([speech isSpeaking]) {
26
+ sleep(WAIT);
27
+ }
28
+
29
+ [pool release];
30
+ }
31
+
32
+ void available_voices(void (*func)(void *, char *), void *data) {
33
+ NSAutoreleasePool *pool;
34
+ NSArray *voices;
35
+ NSEnumerator *itor;
36
+ NSString *voice;
37
+
38
+
39
+ pool = [[NSAutoreleasePool alloc] init];
40
+
41
+ voices = [NSSpeechSynthesizer availableVoices];
42
+ itor = [voices objectEnumerator];
43
+
44
+ while (voice = [itor nextObject]) { // (b)
45
+ char *cvoice = [voice UTF8String];
46
+ func(data, cvoice);
47
+ }
48
+
49
+ [pool release];
50
+ }
51
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: macsay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - winebarrel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-29 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Simple Ruby bindings for NSSpeechSynthesizer.
23
+ email: sgwr_dts@yahoo.co.jp
24
+ executables: []
25
+
26
+ extensions:
27
+ - ext/extconf.rb
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - ext/extconf.rb
32
+ - ext/macsay.c
33
+ - ext/say.m
34
+ - README
35
+ has_rdoc: true
36
+ homepage: https://github.com/winebarrel/infra-study/tree/master/2nd/macsay
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --title
42
+ - MacSay - Simple Ruby bindings for NSSpeechSynthesizer.
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.5.3
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Simple Ruby bindings for NSSpeechSynthesizer.
70
+ test_files: []
71
+