ispeech 1.0.1 → 1.0.2

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.
@@ -2,7 +2,7 @@ require 'uri'
2
2
 
3
3
  module Ispeech
4
4
 
5
- VERSION = "1.0.1"
5
+ VERSION = "1.0.2"
6
6
 
7
7
  class Voice
8
8
  QUALITY_LOW = 8000
@@ -4,6 +4,9 @@ module Ispeech
4
4
  class Voice
5
5
  attr_reader :languages, :speaker, :gender, :quality
6
6
 
7
+ ERROR_VOICE_DOES_NOT_EXIST = Error.new("Voice does not exist.")
8
+ ERROR_NO_VOICE_FOR_OPTIONS = Error.new("No voice exists for the options requested.")
9
+
7
10
  def initialize(speaker, gender, *languages)
8
11
  @speaker = speaker
9
12
  @gender = gender
@@ -72,23 +75,26 @@ module Ispeech
72
75
  named_voice(speaker)
73
76
  else
74
77
  language = options[:language] || :en
75
- gender = options[:gender]
76
- speakers_for_language = self.map[language]
77
-
78
- speakers = case gender
79
- when GENDER_FEMALE
80
- speakers_for_language[GENDER_FEMALE]
81
- when GENDER_MALE
82
- speakers_for_language[GENDER_MALE]
78
+ gender = options[:gender].nil? ? nil : options[:gender].to_sym
79
+ speakers_for_language = self.map[language.to_sym]
80
+
81
+ if speakers_for_language.nil?
82
+ raise ERROR_NO_VOICE_FOR_OPTIONS
83
83
  else
84
- speakers_for_language[GENDER_FEMALE] +
84
+ speakers = case gender
85
+ when GENDER_FEMALE
86
+ speakers_for_language[GENDER_FEMALE]
87
+ when GENDER_MALE
85
88
  speakers_for_language[GENDER_MALE]
86
- end
89
+ else
90
+ speakers_for_language[GENDER_FEMALE] + speakers_for_language[GENDER_MALE]
91
+ end
87
92
 
88
- if speakers.empty?
89
- nil
90
- else
91
- named_voice(speakers.sample)
93
+ if speakers.empty?
94
+ raise ERROR_NO_VOICE_FOR_OPTIONS
95
+ else
96
+ named_voice(speakers.sample)
97
+ end
92
98
  end
93
99
  end
94
100
  end
@@ -113,7 +119,7 @@ module Ispeech
113
119
  if info = @@voices[speaker.to_s.downcase.to_sym]
114
120
  info
115
121
  else
116
- raise Error.new("Voice does not exist.")
122
+ raise ERROR_VOICE_DOES_NOT_EXIST
117
123
  end
118
124
  end
119
125
 
@@ -6,6 +6,7 @@ module Ispeech
6
6
  CLIENT_ENVIRONMENT = "RUBY_#{RUBY_VERSION}"
7
7
 
8
8
  ERROR_MISSING_CONFIG = Error.new("VoiceService requires configuration.")
9
+ ERROR_MISSING_VOICE = Error.new("Voice generation requires a voice.")
9
10
 
10
11
  attr_reader :config
11
12
 
@@ -31,6 +32,8 @@ module Ispeech
31
32
  end
32
33
 
33
34
  def generate_with_voice(text, voice)
35
+ raise ERROR_MISSING_VOICE unless voice.is_a?(Ispeech::Voice)
36
+
34
37
  params = {
35
38
  # API Defaults:
36
39
  # :bitrate => 48,
@@ -63,6 +63,12 @@ describe Ispeech::VoiceService do
63
63
  pending("Without mock, the returned file quality needs to be confirmed")
64
64
  end
65
65
  end
66
+
67
+ it 'should throw an error if no custom voice is given' do
68
+ expect do
69
+ service.generate_with_voice(text_string, nil)
70
+ end.to raise_error(Ispeech::Error, Ispeech::VoiceService::ERROR_MISSING_VOICE.message)
71
+ end
66
72
  end
67
73
 
68
74
  end
@@ -28,7 +28,7 @@ describe Ispeech::Voice do
28
28
  it 'should throw an error if the voice does not exist' do
29
29
  expect do
30
30
  Ispeech::Voice.named_voice('Birkir')
31
- end.to raise_error(Ispeech::Error, "Voice does not exist.")
31
+ end.to raise_error(Ispeech::Voice::ERROR_VOICE_DOES_NOT_EXIST)
32
32
  end
33
33
 
34
34
  it 'should return the active voice map' do
@@ -66,6 +66,12 @@ describe Ispeech::Voice do
66
66
  (DEFAULT_ENGLISH_FEMALE_TEST_VOICES + DEFAULT_ENGLISH_MALE_TEST_VOICES).should include(voice.speaker)
67
67
  end
68
68
 
69
+ it 'throws error, with non existing speaker' do
70
+ expect do
71
+ Ispeech::Voice.extract_from_options(:speaker => 'Zorg')
72
+ end.to raise_error(Ispeech::Voice::ERROR_VOICE_DOES_NOT_EXIST)
73
+ end
74
+
69
75
  it 'specifies a speaker' do
70
76
  voice = Ispeech::Voice.extract_from_options(:speaker => 'antoine')
71
77
  voice.speaker.should == 'Antoine'
@@ -78,6 +84,12 @@ describe Ispeech::Voice do
78
84
  voice.speaker.should == 'Rosa'
79
85
  end
80
86
 
87
+ it 'throws error, with non existing language' do
88
+ expect do
89
+ Ispeech::Voice.extract_from_options(:language => :vorgon)
90
+ end.to raise_error(Ispeech::Voice::ERROR_NO_VOICE_FOR_OPTIONS)
91
+ end
92
+
81
93
  it 'specifies a language and no gender' do
82
94
  voice = Ispeech::Voice.extract_from_options(:language => :fr)
83
95
  voice.should_not be_nil
@@ -87,10 +99,14 @@ describe Ispeech::Voice do
87
99
  it 'specifies a language and gender' do
88
100
  voice = Ispeech::Voice.extract_from_options(:language => :es, :gender => Ispeech::Voice::GENDER_FEMALE)
89
101
  voice.speaker.should == 'Rosa'
102
+ end
90
103
 
91
- voice = Ispeech::Voice.extract_from_options(:language => :es, :gender => Ispeech::Voice::GENDER_MALE)
92
- voice.should be_nil
104
+ it 'throws error, with non existing language gender' do
105
+ expect do
106
+ puts Ispeech::Voice.extract_from_options(:language => :es, :gender => :male)
107
+ end.to raise_error(Ispeech::Voice::ERROR_NO_VOICE_FOR_OPTIONS)
93
108
  end
109
+
94
110
  end
95
111
  end
96
112
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ispeech
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-24 00:00:00.000000000 Z
12
+ date: 2012-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: backports