loquendo-wrapper 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Patrick Ximenes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # Loquendo
2
+
3
+ Ruby wrapper for Loquendo TTS
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'loquendo-wrapper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install loquendo-wrapper
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require "loquendo"
23
+
24
+ data = Loquendo.convert("the book is on de table")
25
+
26
+ file = File.new("/tmp/sound.alaw", "w")
27
+ file.write(data)
28
+ file.close
29
+ ```
30
+
31
+ ## Author
32
+
33
+ Copyright (c) 2012 Patrick Ximenes. MIT licence (see LICENSE for details).
34
+
@@ -0,0 +1,94 @@
1
+ require 'tempfile'
2
+ require 'loquendo/version'
3
+
4
+ class Loquendo
5
+
6
+ VALID_VOICES = [:fernanda, :ludoviko]
7
+
8
+ attr_accessor :command_dir, :command, :voice, :sound_dir, :sound_file
9
+
10
+ class CommandNotFound < Exception; end
11
+ class InvalidVoice < Exception; end
12
+
13
+ def initialize(opts = {})
14
+ @command_dir = opts[:command_dir] || '/opt/Loquendo/LTTS7/bin'
15
+ @command = opts[:command] || 'SaveFile-alaw'
16
+ @sound_dir = opts[:sound_dir] || Dir::tmpdir
17
+ @sound_file = opts[:sound_file] || 'ltts'
18
+ @voice = opts[:voice] || :fernanda
19
+ self.session = opts[:session] || '/opt/Loquendo/LTTS7/bin/default.session'
20
+ end
21
+
22
+ def self.convert(string, opts = {})
23
+ ltts = Loquendo.new(opts)
24
+ ltts.convert(string)
25
+ end
26
+
27
+ def self.convert_to_file(string, opts = {})
28
+ ltts = Loquendo.new(opts)
29
+ ltts.convert_to_file(string)
30
+ end
31
+
32
+ def session
33
+ ENV['LTTS7_DEFAULTSESSION']
34
+ end
35
+
36
+ def session=(default_session)
37
+ ENV['LTTS7_DEFAULTSESSION'] = default_session
38
+ end
39
+
40
+ def convert(string)
41
+ check_for_command
42
+ validate_voice
43
+ _convert(string)
44
+ end
45
+
46
+ def convert_to_file(string)
47
+ check_for_command
48
+ validate_voice
49
+ _convert_to_file(string)
50
+ end
51
+
52
+ def command_path
53
+ command_dir + '/' + command
54
+ end
55
+
56
+ def sound_path
57
+ sound_dir + '/' + sound_file
58
+ end
59
+
60
+ private
61
+
62
+ def check_for_command
63
+ if !File.exists?(command_path) || !File.executable?(command_path)
64
+ raise CommandNotFound, "Command #{command_path} not found or not executable"
65
+ end
66
+ end
67
+
68
+ def validate_voice
69
+ if !is_valid_voice?
70
+ raise InvalidVoice, "Voice '#{voice.to_s}' is not a valid voice"
71
+ end
72
+ end
73
+
74
+ def is_valid_voice?
75
+ Loquendo::VALID_VOICES.include?(voice)
76
+ end
77
+
78
+ def _convert_to_file(string)
79
+ system("#{command_path} #{voice.to_s} \"#{string}\" \"#{sound_path}\"")
80
+ end
81
+
82
+ def _convert(string)
83
+ result = nil
84
+ temp_file = Tempfile.new(sound_file, sound_dir)
85
+
86
+ if system("#{command_path} #{voice.to_s} \"#{string}\" \"#{temp_file.path}\"")
87
+ result = File.read(temp_file.path)
88
+ end
89
+
90
+ temp_file.unlink
91
+ return result
92
+ end
93
+
94
+ end
@@ -0,0 +1,3 @@
1
+ class Loquendo
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'loquendo/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'loquendo-wrapper'
7
+ s.version = Loquendo::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Patrick Ximenes']
10
+ s.date = Time.now.strftime("%Y-%m-%d")
11
+ s.email = ['hexaclamys@gmail.com']
12
+ s.homepage = 'https://github.com/hexams/loquendo-wrapper'
13
+ s.summary = %q{Ruby wrapper for Loquendo TTS.}
14
+ s.description = %q{Ruby wrapper for Loquendo TTS using sample SaveFile[-alaw] command.}
15
+
16
+ s.extra_rdoc_files = ['README.md']
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ['lib']
22
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loquendo-wrapper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Patrick Ximenes
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-16 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Ruby wrapper for Loquendo TTS using sample SaveFile[-alaw] command.
23
+ email:
24
+ - hexaclamys@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.md
31
+ files:
32
+ - LICENSE
33
+ - README.md
34
+ - lib/loquendo.rb
35
+ - lib/loquendo/version.rb
36
+ - loquendo-wrapper.gemspec
37
+ has_rdoc: true
38
+ homepage: https://github.com/hexams/loquendo-wrapper
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.6.2
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Ruby wrapper for Loquendo TTS.
71
+ test_files: []
72
+