neospeech 1.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in neospeech.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Abhishek Anand
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,29 @@
1
+ # Neospeech
2
+
3
+ Ruby wrapper for NeoSpeech Text to Speech API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'neospeech'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install neospeech
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ require "neospeech/version"
2
+ require "neospeech/string"
3
+ require "neospeech/convertor"
4
+
5
+ module Neospeech
6
+
7
+ mattr_accessor :email, :account_id, :login_key, :login_password
8
+
9
+ def self.setup
10
+ yield self
11
+ end
12
+
13
+ def self.account_auth
14
+ {
15
+ email: email,
16
+ account_id: account_id
17
+ }
18
+ end
19
+
20
+ def self.api_auth
21
+ {
22
+ login_key: login_key,
23
+ login_password: login_password
24
+ }
25
+ end
26
+ end
@@ -0,0 +1,107 @@
1
+ require "httparty"
2
+ class Neospeech::Convertor
3
+ include ::HTTParty
4
+ base_uri 'https://tts.neospeech.com'
5
+ RELATIVE_URL = '/rest_1_1.php'
6
+
7
+ attr_reader :status
8
+ attr_accessor :audio_file_url, :error, :text, :voice, :speed, :pitch, :volume
9
+
10
+ def initialize(args)
11
+ args.each { |key, value| send(key.to_s+'=', value) }
12
+ @response = {}
13
+ self
14
+ end
15
+
16
+ def queue
17
+ @response = simple
18
+ @status = @response['statusCode']
19
+ error = @response['resultCode']
20
+ self
21
+ end
22
+
23
+ def conversion_number
24
+ @response['conversionNumber']
25
+ end
26
+
27
+ def finished?
28
+ error || success?
29
+ end
30
+
31
+ def success?
32
+ status.eql?('4')
33
+ end
34
+
35
+ def status
36
+ unless @status.eql?('4')
37
+ response = query_status['response']
38
+ if response['resultCode'] == '0'
39
+ @status = response['statusCode']
40
+ @audio_file_url = response['downloadUrl'] if @status.eql?('4')
41
+
42
+ end
43
+ end
44
+ @status
45
+ end
46
+
47
+ def error= resultCode
48
+ @error = resultCode.eql?('0') ? nil : resultCode
49
+ end
50
+
51
+ def audio_file_url
52
+ error || @audio_file_url
53
+ end
54
+
55
+ def voice= name
56
+ @voice = name ? "TTS_#{name.upcase}_DB" : 'TTS_KATE_DB'
57
+ end
58
+
59
+ def speed= value
60
+ @speed = case(value.to_s)
61
+ when 'very slow'
62
+ '50'
63
+ when 'slow'
64
+ '75'
65
+ when 'normal'
66
+ '100'
67
+ when 'fast'
68
+ '200'
69
+ when 'very fast'
70
+ '400'
71
+ else
72
+ '50'
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def query_status
79
+ options = [::Neospeech.account_auth, {conversionNumber: conversion_number}].reduce(:merge)
80
+ body_xml = prepare_xml options, 'GetConversionStatus'
81
+ response = self.class.post(RELATIVE_URL, body: body_xml).parsed_response
82
+ error = response['response']['resultCode']
83
+ response
84
+ end
85
+
86
+ def simple
87
+ options = [::Neospeech.account_auth, ::Neospeech.api_auth, settings, {text: text}].reduce(:merge)
88
+ body_xml = prepare_xml options, 'ConvertSimple'
89
+ self.class.post(RELATIVE_URL, body: body_xml).parsed_response['response']
90
+ end
91
+
92
+ def settings
93
+ {
94
+ voice: voice,
95
+ output_format: 'FORMAT_WAV',
96
+ sample_rate: '16',
97
+ speed: speed,
98
+ volume: volume,
99
+ pitch: pitch
100
+ }.delete_if {|k,v| v.blank?}
101
+ end
102
+
103
+ def prepare_xml options={}, method
104
+ options = options.inject({}) { |h, q| h[q[0].to_s.camelcase(:lower)] = q[1]; h }
105
+ options.to_xml(:skip_instruct => true, :root => method)
106
+ end
107
+ end
@@ -0,0 +1,12 @@
1
+ module Neospeech
2
+ module String
3
+ def speak voice, speed = 'normal'
4
+ conversion = Neospeech::Convertor.new text: self, voice: voice, speed: speed
5
+ conversion.queue
6
+ sleep(1) until conversion.finished?
7
+ conversion.audio_file_url
8
+ end
9
+ end
10
+ end
11
+
12
+ String.send(:include, Neospeech::String)
@@ -0,0 +1,3 @@
1
+ module Neospeech
2
+ VERSION = "1.0.0.pre"
3
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/neospeech/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Abhishek Anand"]
6
+ gem.email = ["r3d.d7a90n@gmail.com"]
7
+ gem.description = %q{Ruby wrapper for NeoSpeech Text to Speech API}
8
+ gem.summary = %q{Ruby wrapper for NeoSpeech Text to Speech API}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "neospeech"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Neospeech::VERSION
17
+ gem.add_runtime_dependency 'httparty'
18
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neospeech
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Abhishek Anand
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Ruby wrapper for NeoSpeech Text to Speech API
31
+ email:
32
+ - r3d.d7a90n@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - lib/neospeech.rb
43
+ - lib/neospeech/convertor.rb
44
+ - lib/neospeech/string.rb
45
+ - lib/neospeech/version.rb
46
+ - neospeech.gemspec
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>'
63
+ - !ruby/object:Gem::Version
64
+ version: 1.3.1
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Ruby wrapper for NeoSpeech Text to Speech API
71
+ test_files: []