yandex_speech_api 1.1.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/README.md +42 -88
- data/lib/yandex_speech.rb +61 -146
- data/lib/yandex_speech/connection.rb +21 -39
- data/lib/yandex_speech/project_structure.rb +3 -15
- data/lib/yandex_speech/setters.rb +78 -0
- data/lib/yandex_speech/sounds.rb +38 -0
- data/lib/yandex_speech/speaker.rb +26 -67
- data/spec/yandex_speech/mp3_player/base_spec.rb +1 -2
- data/spec/yandex_speech_spec.rb +21 -38
- metadata +4 -23
- data/lib/yandex_speech/emotion.rb +0 -39
- data/lib/yandex_speech/format.rb +0 -38
- data/lib/yandex_speech/helpers.rb +0 -52
- data/lib/yandex_speech/key.rb +0 -106
- data/lib/yandex_speech/language.rb +0 -59
- data/lib/yandex_speech/mp3_player.rb +0 -33
- data/lib/yandex_speech/speed.rb +0 -60
- data/lib/yandex_speech/voice.rb +0 -45
- data/spec/yandex_speech/emotion_spec.rb +0 -34
- data/spec/yandex_speech/format_spec.rb +0 -30
- data/spec/yandex_speech/key_spec.rb +0 -58
- data/spec/yandex_speech/language_spec.rb +0 -36
- data/spec/yandex_speech/mp3_player_spec.rb +0 -23
- data/spec/yandex_speech/speed_spec.rb +0 -33
- data/spec/yandex_speech/voice_spec.rb +0 -28
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex_speech_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuzichev Michael
|
@@ -23,31 +23,18 @@ files:
|
|
23
23
|
- README.md
|
24
24
|
- lib/yandex_speech.rb
|
25
25
|
- lib/yandex_speech/connection.rb
|
26
|
-
- lib/yandex_speech/emotion.rb
|
27
|
-
- lib/yandex_speech/format.rb
|
28
|
-
- lib/yandex_speech/helpers.rb
|
29
|
-
- lib/yandex_speech/key.rb
|
30
|
-
- lib/yandex_speech/language.rb
|
31
|
-
- lib/yandex_speech/mp3_player.rb
|
32
26
|
- lib/yandex_speech/mp3_player/base.rb
|
33
27
|
- lib/yandex_speech/mp3_player/linux_mp3_player.rb
|
34
28
|
- lib/yandex_speech/mp3_player/mac_mp3_player.rb
|
35
29
|
- lib/yandex_speech/project_structure.rb
|
30
|
+
- lib/yandex_speech/setters.rb
|
31
|
+
- lib/yandex_speech/sounds.rb
|
36
32
|
- lib/yandex_speech/speaker.rb
|
37
|
-
- lib/yandex_speech/speed.rb
|
38
|
-
- lib/yandex_speech/voice.rb
|
39
33
|
- spec/spec_helper.rb
|
40
34
|
- spec/yandex_speech/connection_spec.rb
|
41
|
-
- spec/yandex_speech/emotion_spec.rb
|
42
|
-
- spec/yandex_speech/format_spec.rb
|
43
35
|
- spec/yandex_speech/helpers_spec.rb
|
44
|
-
- spec/yandex_speech/key_spec.rb
|
45
|
-
- spec/yandex_speech/language_spec.rb
|
46
36
|
- spec/yandex_speech/mp3_player/base_spec.rb
|
47
37
|
- spec/yandex_speech/mp3_player/linux_mp3_player_spec.rb
|
48
|
-
- spec/yandex_speech/mp3_player_spec.rb
|
49
|
-
- spec/yandex_speech/speed_spec.rb
|
50
|
-
- spec/yandex_speech/voice_spec.rb
|
51
38
|
- spec/yandex_speech_spec.rb
|
52
39
|
homepage: https://github.com/Medvedu/Yandex-Speech-API
|
53
40
|
licenses:
|
@@ -68,6 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
55
|
- !ruby/object:Gem::Version
|
69
56
|
version: '0'
|
70
57
|
requirements:
|
58
|
+
- afplay
|
71
59
|
- mpg123
|
72
60
|
rubyforge_project:
|
73
61
|
rubygems_version: 2.5.1
|
@@ -75,16 +63,9 @@ signing_key:
|
|
75
63
|
specification_version: 4
|
76
64
|
summary: Text to speech translation
|
77
65
|
test_files:
|
78
|
-
- spec/yandex_speech/language_spec.rb
|
79
66
|
- spec/yandex_speech/connection_spec.rb
|
80
|
-
- spec/yandex_speech/key_spec.rb
|
81
67
|
- spec/yandex_speech/helpers_spec.rb
|
82
68
|
- spec/yandex_speech/mp3_player/linux_mp3_player_spec.rb
|
83
69
|
- spec/yandex_speech/mp3_player/base_spec.rb
|
84
|
-
- spec/yandex_speech/speed_spec.rb
|
85
|
-
- spec/yandex_speech/emotion_spec.rb
|
86
|
-
- spec/yandex_speech/format_spec.rb
|
87
|
-
- spec/yandex_speech/voice_spec.rb
|
88
|
-
- spec/yandex_speech/mp3_player_spec.rb
|
89
70
|
- spec/spec_helper.rb
|
90
71
|
- spec/yandex_speech_spec.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module YandexSpeechApi
|
4
|
-
class Emotion
|
5
|
-
|
6
|
-
##
|
7
|
-
# List of allowed emotions
|
8
|
-
#
|
9
|
-
# @return [Array<String>]
|
10
|
-
|
11
|
-
def self.list
|
12
|
-
%i(evil good neutral)
|
13
|
-
end
|
14
|
-
|
15
|
-
#
|
16
|
-
# @return [Symbol]
|
17
|
-
# possible values: :evil, :good or :neutral
|
18
|
-
|
19
|
-
attr_reader :type
|
20
|
-
|
21
|
-
def initialize(emotion)
|
22
|
-
@type = emotion.downcase.to_sym
|
23
|
-
|
24
|
-
raise EmotionNotAllowed, emotion unless emotion_known? @type
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def emotion_known?(emotion)
|
30
|
-
Emotion.list.include? emotion
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# Raised when unknown emotion has been selected.
|
35
|
-
|
36
|
-
class EmotionNotAllowed < YandexSpeechError
|
37
|
-
def initialize(emotion); super "Emotion '#{emotion}' not allowed for usage. To see list of allowed emotions use Emotion#list" end; end
|
38
|
-
end # class Emotion
|
39
|
-
end # module YandexSpeechApi
|
data/lib/yandex_speech/format.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module YandexSpeechApi
|
4
|
-
class Format
|
5
|
-
|
6
|
-
##
|
7
|
-
# List of allowed formats
|
8
|
-
#
|
9
|
-
# @return [Array<String>]
|
10
|
-
|
11
|
-
def self.list
|
12
|
-
%i(mp3 wav opus)
|
13
|
-
end
|
14
|
-
|
15
|
-
# @return [Symbol]
|
16
|
-
# possible values: :mp3, :wav or :opus
|
17
|
-
|
18
|
-
attr_reader :type
|
19
|
-
|
20
|
-
def initialize(format)
|
21
|
-
@type = format.downcase.to_sym
|
22
|
-
|
23
|
-
raise FormatNotAllowed, format unless format_known? @type
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def format_known?(format)
|
29
|
-
Format.list.include? format
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
# Raised when unknown format has been selected.
|
34
|
-
|
35
|
-
class FormatNotAllowed < YandexSpeechError
|
36
|
-
def initialize(format); super "Format '#{format}' not allowed for usage. To see list of allowed formats use Format#list" end; end
|
37
|
-
end # class Format
|
38
|
-
end # module YandexSpeechApi
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module YandexSpeechApi
|
4
|
-
module Helpers
|
5
|
-
|
6
|
-
##
|
7
|
-
# From what OS we launched?
|
8
|
-
#
|
9
|
-
# @example #1
|
10
|
-
# recognize_operation_system # ==> :linux
|
11
|
-
#
|
12
|
-
# @example #2
|
13
|
-
# recognize_operation_system # ==> :unknown
|
14
|
-
#
|
15
|
-
# @return [Symbol]
|
16
|
-
# OS name
|
17
|
-
|
18
|
-
def self.recognize_operation_system
|
19
|
-
case RbConfig::CONFIG['host_os']
|
20
|
-
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
21
|
-
:windows
|
22
|
-
when /darwin|mac os/
|
23
|
-
:mac_os
|
24
|
-
when /linux/
|
25
|
-
:linux
|
26
|
-
else
|
27
|
-
:unknown
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
##
|
32
|
-
# Searches pathname for executable +cmd+.
|
33
|
-
#
|
34
|
-
# @return [Pathname, NilClass]
|
35
|
-
# Returns +Pathname+ if +cmd+ is present and executable.
|
36
|
-
# If search unsuccessful it returns +nil+.
|
37
|
-
|
38
|
-
def self.find_executable(cmd)
|
39
|
-
possible_extensions = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
40
|
-
|
41
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
42
|
-
possible_extensions.each do |extension|
|
43
|
-
exe = Pathname.new(File.join(path, "#{cmd}#{extension}"))
|
44
|
-
|
45
|
-
return exe if exe.executable? && exe.file?
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
return nil # search unsuccessful
|
50
|
-
end
|
51
|
-
end # module Helpers
|
52
|
-
end # module YandexSpeechApi
|
data/lib/yandex_speech/key.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module YandexSpeechApi
|
4
|
-
class Key
|
5
|
-
class << self
|
6
|
-
|
7
|
-
##
|
8
|
-
# Sets global key.
|
9
|
-
#
|
10
|
-
# @param [Key, Symbol] new_key
|
11
|
-
#
|
12
|
-
# @exception InvalidGlobalKey
|
13
|
-
# raised when +new_key+ param have unexpected class.
|
14
|
-
|
15
|
-
def global_key=(new_key)
|
16
|
-
key_tmp = new_key.is_a?(Key) ? new_key : Key.new(new_key)
|
17
|
-
raise InvalidGlobalKey, key_tmp unless key_tmp.present?
|
18
|
-
@global_key = key_tmp
|
19
|
-
end
|
20
|
-
|
21
|
-
##
|
22
|
-
# @return [TrueClass, FalseClass]
|
23
|
-
# True if global key set, otherwise returns false.
|
24
|
-
|
25
|
-
def global_key?
|
26
|
-
!!global_key
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
##
|
32
|
-
# @return [Key, nil]
|
33
|
-
|
34
|
-
def global_key
|
35
|
-
@global_key
|
36
|
-
end
|
37
|
-
end # class << self
|
38
|
-
|
39
|
-
def initialize(key)
|
40
|
-
@instance_key = key
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# Returns an key.
|
45
|
-
#
|
46
|
-
# @exception KeyNotDefined
|
47
|
-
# raised if both +instance key+ and +global key_ are not present
|
48
|
-
#
|
49
|
-
# @return [Key]
|
50
|
-
|
51
|
-
def get
|
52
|
-
if present?
|
53
|
-
return instance_key
|
54
|
-
elsif default?
|
55
|
-
return default.get
|
56
|
-
else
|
57
|
-
raise KeyNotDefined
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
##
|
62
|
-
# Key present?
|
63
|
-
#
|
64
|
-
# @return [TrueClass, FalseClass]
|
65
|
-
# returns +false+ if key is +:unknown+, otherwise - +true+.
|
66
|
-
|
67
|
-
def present?
|
68
|
-
!(instance_key == :unknown)
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
# @return [Symbol, String]
|
74
|
-
# possible values: :unknown or some string
|
75
|
-
|
76
|
-
attr_reader :instance_key
|
77
|
-
|
78
|
-
##
|
79
|
-
# @return [TrueClass, FalseClass]
|
80
|
-
# @see Key#global_key?
|
81
|
-
|
82
|
-
def default?
|
83
|
-
Key.global_key?
|
84
|
-
end
|
85
|
-
|
86
|
-
##
|
87
|
-
# @return [Key, nil]
|
88
|
-
# see Key#global_key
|
89
|
-
|
90
|
-
def default
|
91
|
-
Key.instance_variable_get :@global_key
|
92
|
-
end
|
93
|
-
|
94
|
-
##
|
95
|
-
# Raised when user tries to call #say method without key.
|
96
|
-
|
97
|
-
class KeyNotDefined < YandexSpeechError
|
98
|
-
def initialize; super "WARNING! You initialized Speaker class without key! It means you can not use YandexSpeechApi service. You can get your key there: https://tech.yandex.ru/speechkit" end; end
|
99
|
-
|
100
|
-
##
|
101
|
-
# Raised when global key going to be set with default values.
|
102
|
-
|
103
|
-
class InvalidGlobalKey < YandexSpeechError
|
104
|
-
def initialize(key); super "Global key '#{key}' can not been nil or :unknown" end; end
|
105
|
-
end # class Key
|
106
|
-
end # module YandexSpeechApi
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module YandexSpeechApi
|
4
|
-
class Language # no-doc
|
5
|
-
|
6
|
-
##
|
7
|
-
# List of allowed languages
|
8
|
-
#
|
9
|
-
# @return [Array<Classes>]
|
10
|
-
|
11
|
-
def self.allowed_languages
|
12
|
-
@cached_list ||= Array(codes.keys)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.codes # no-doc
|
16
|
-
{
|
17
|
-
english: 'en-US',
|
18
|
-
russian: 'ru‑RU',
|
19
|
-
turkey: 'tr-TR',
|
20
|
-
ukrain: 'uk-UK',
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [Symbol]
|
25
|
-
|
26
|
-
attr_reader :language
|
27
|
-
|
28
|
-
# @return [String]
|
29
|
-
|
30
|
-
def code
|
31
|
-
@code ||= Language.codes[@language]
|
32
|
-
end
|
33
|
-
|
34
|
-
##
|
35
|
-
# Creates new object instance.
|
36
|
-
#
|
37
|
-
# @param [String] language
|
38
|
-
# Selected language.
|
39
|
-
#
|
40
|
-
# @exception UnknownLanguageError
|
41
|
-
# Raised when language is unknown
|
42
|
-
#
|
43
|
-
# @return [Language]
|
44
|
-
|
45
|
-
def initialize(language)
|
46
|
-
@language = language.downcase.to_sym
|
47
|
-
|
48
|
-
unless Language.allowed_languages.include? @language
|
49
|
-
raise UnknownLanguageError, @language
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
##
|
54
|
-
# Raised when unknown language has been selected.
|
55
|
-
|
56
|
-
class UnknownLanguageError < YandexSpeechError
|
57
|
-
def initialize(lang); super "Unknown language selected: '#{lang}'. See Language#allowed_languages for list of allowed languages" end; end
|
58
|
-
end # class Language
|
59
|
-
end # module YandexSpeechApi
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module YandexSpeechApi
|
4
|
-
module MP3_Player
|
5
|
-
|
6
|
-
##
|
7
|
-
# Creates MP3 player instance. Depends from OS.
|
8
|
-
#
|
9
|
-
# @exception UnknownOsError
|
10
|
-
# raised when OS unknown.
|
11
|
-
#
|
12
|
-
# @return [Linux_MP3_Player, Mac_MP3_Player]
|
13
|
-
|
14
|
-
def self.init
|
15
|
-
@player ||=
|
16
|
-
case Helpers::recognize_operation_system
|
17
|
-
when :linux
|
18
|
-
Linux_MP3_Player.new
|
19
|
-
when :mac_os
|
20
|
-
Mac_MP3_Player.new
|
21
|
-
else
|
22
|
-
raise UnknownOs
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
##
|
27
|
-
# Raised when MP3_Player#init can not recognize what operation system is
|
28
|
-
# used.
|
29
|
-
|
30
|
-
class UnknownOs < YandexSpeechError
|
31
|
-
def initialize; super "#{self.class}#recognize_operation_system cannot recognize your operation system!"; end; end
|
32
|
-
end # module Player
|
33
|
-
end # module YandexSpeechApi
|
data/lib/yandex_speech/speed.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module YandexSpeechApi
|
4
|
-
class Speed
|
5
|
-
class << self
|
6
|
-
|
7
|
-
# @example #1
|
8
|
-
# list[:slow] # ==> 0.5
|
9
|
-
#
|
10
|
-
# @example #2
|
11
|
-
# list[:wrong_key] # ==> nil
|
12
|
-
#
|
13
|
-
# @return [Hash]
|
14
|
-
|
15
|
-
def modes
|
16
|
-
{
|
17
|
-
:slowest => 0.1, # minimal allowed speed
|
18
|
-
:slow => 0.5,
|
19
|
-
:standard => 1.0, # default
|
20
|
-
:fast => 1.5,
|
21
|
-
:fastest => 3.0 # maximal allowed speed
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end # class << self
|
25
|
-
|
26
|
-
# @return [Float]
|
27
|
-
# In range [(0.1)..3.0]
|
28
|
-
|
29
|
-
attr_reader :value
|
30
|
-
|
31
|
-
def initialize(speed)
|
32
|
-
@value = if speed.is_a? Numeric
|
33
|
-
speed.round 2
|
34
|
-
else
|
35
|
-
Speed.modes[speed.downcase.to_sym]
|
36
|
-
end
|
37
|
-
|
38
|
-
raise SpeedModeNotAllowed, speed if @value.nil?
|
39
|
-
raise SpeedValueNotInRange, @value unless speed_in_valid_range? @value
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def speed_in_valid_range?(number)
|
45
|
-
number.between? 0.1, 3
|
46
|
-
end
|
47
|
-
|
48
|
-
##
|
49
|
-
# Raised when speed mode is unknown.
|
50
|
-
|
51
|
-
class SpeedModeNotAllowed < YandexSpeechError
|
52
|
-
def initialize(speed); super "Speed '#{speed}' not allowed for usage. To see list of allowed formats use Emotion#list." end; end
|
53
|
-
|
54
|
-
##
|
55
|
-
# Raised when +speed+ param is not in [(0.1)..3] range.
|
56
|
-
|
57
|
-
class SpeedValueNotInRange < YandexSpeechError
|
58
|
-
def initialize(value); super "Speed value '#{value}' should be from [(0.1)..3] range" end; end
|
59
|
-
end # class Speed
|
60
|
-
end # module YandexSpeechApi
|