yandex_speech_api 1.1.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.
- checksums.yaml +7 -0
- data/Gemfile +16 -0
- data/LICENSE +9 -0
- data/README.md +101 -0
- data/lib/yandex_speech.rb +253 -0
- data/lib/yandex_speech/connection.rb +52 -0
- data/lib/yandex_speech/emotion.rb +39 -0
- data/lib/yandex_speech/format.rb +38 -0
- data/lib/yandex_speech/helpers.rb +52 -0
- data/lib/yandex_speech/key.rb +106 -0
- data/lib/yandex_speech/language.rb +59 -0
- data/lib/yandex_speech/mp3_player.rb +33 -0
- data/lib/yandex_speech/mp3_player/base.rb +72 -0
- data/lib/yandex_speech/mp3_player/linux_mp3_player.rb +41 -0
- data/lib/yandex_speech/mp3_player/mac_mp3_player.rb +22 -0
- data/lib/yandex_speech/project_structure.rb +30 -0
- data/lib/yandex_speech/speaker.rb +103 -0
- data/lib/yandex_speech/speed.rb +60 -0
- data/lib/yandex_speech/voice.rb +45 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/yandex_speech/connection_spec.rb +24 -0
- data/spec/yandex_speech/emotion_spec.rb +34 -0
- data/spec/yandex_speech/format_spec.rb +30 -0
- data/spec/yandex_speech/helpers_spec.rb +20 -0
- data/spec/yandex_speech/key_spec.rb +58 -0
- data/spec/yandex_speech/language_spec.rb +36 -0
- data/spec/yandex_speech/mp3_player/base_spec.rb +25 -0
- data/spec/yandex_speech/mp3_player/linux_mp3_player_spec.rb +39 -0
- data/spec/yandex_speech/mp3_player_spec.rb +23 -0
- data/spec/yandex_speech/speed_spec.rb +33 -0
- data/spec/yandex_speech/voice_spec.rb +28 -0
- data/spec/yandex_speech_spec.rb +112 -0
- metadata +90 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# Skips tests when OS-platform is not unix-like.
|
|
7
|
+
#
|
|
8
|
+
# @return [TrueClass, FalseClass]
|
|
9
|
+
# +True+ and tests below be SKIPPED.
|
|
10
|
+
# +False+ otherwise.
|
|
11
|
+
|
|
12
|
+
def depends_on_platform
|
|
13
|
+
!(RbConfig::CONFIG['host_os'] =~ /linux/)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# ----------------------------------------------------
|
|
17
|
+
|
|
18
|
+
module YandexSpeechApi
|
|
19
|
+
module MP3_Player
|
|
20
|
+
describe Linux_MP3_Player, disabled: depends_on_platform do
|
|
21
|
+
context '#play' do
|
|
22
|
+
before :each do # stub parent class methods
|
|
23
|
+
expect_any_instance_of(described_class)
|
|
24
|
+
.to receive(:validate_file_presence).and_return nil
|
|
25
|
+
|
|
26
|
+
expect_any_instance_of(described_class)
|
|
27
|
+
.to receive(:validate_mp3_format).and_return nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'raises an exception when mpg123 not found' do
|
|
31
|
+
allow(Helpers).to receive(:find_executable).and_return nil
|
|
32
|
+
|
|
33
|
+
expect{described_class.new.play('lalalala.')}
|
|
34
|
+
.to raise_exception described_class::ApplicationNotInstalled
|
|
35
|
+
end
|
|
36
|
+
end # context '#play'
|
|
37
|
+
end # describe Linux_MP3_Player
|
|
38
|
+
end # module MP3_Player
|
|
39
|
+
end # module YandexSpeechApi
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module YandexSpeechApi
|
|
6
|
+
describe MP3_Player do
|
|
7
|
+
context '#init' do
|
|
8
|
+
it 'raises an exception if mp3_player cannot been created' do
|
|
9
|
+
allow(Helpers).to receive(:recognize_operation_system)
|
|
10
|
+
.and_return 'unknown'
|
|
11
|
+
|
|
12
|
+
expect{MP3_Player.init}.to raise_exception MP3_Player::UnknownOs
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'creates an mp3_player instance' do
|
|
16
|
+
allow(Helpers).to receive(:recognize_operation_system)
|
|
17
|
+
.and_return :linux
|
|
18
|
+
|
|
19
|
+
expect(MP3_Player.init).to be_instance_of MP3_Player::Linux_MP3_Player
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end # describe MP3_Player
|
|
23
|
+
end # module YandexSpeechApi
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module YandexSpeechApi
|
|
6
|
+
describe Speed do
|
|
7
|
+
context '#new' do
|
|
8
|
+
it 'raises an exception for unknown speed mode' do
|
|
9
|
+
expect { described_class.new :lol }
|
|
10
|
+
.to raise_exception described_class::SpeedModeNotAllowed
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'creates object instance when +speed+ is a symbol' do
|
|
14
|
+
expect(described_class.new(:slowest)).to be
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'creates object instance when +speed+ is an integer' do
|
|
18
|
+
expect(described_class.new(2.45)).to be
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'raises an exception when +speed+ is not in allowed range' do
|
|
22
|
+
expect { described_class.new 5000 }
|
|
23
|
+
.to raise_exception described_class::SpeedValueNotInRange
|
|
24
|
+
end
|
|
25
|
+
end # context #new
|
|
26
|
+
|
|
27
|
+
context '#list' do
|
|
28
|
+
it 'shows list of allowed speed modes' do
|
|
29
|
+
expect(described_class.modes).to_not be_nil
|
|
30
|
+
end
|
|
31
|
+
end # context #list
|
|
32
|
+
end # describe Speed
|
|
33
|
+
end # module YandexSpeechApi
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module YandexSpeechApi
|
|
6
|
+
describe Voice do
|
|
7
|
+
context '#new' do
|
|
8
|
+
it 'raises an exception for unknown voice' do
|
|
9
|
+
expect { described_class.new :some_random_voice }
|
|
10
|
+
.to raise_exception described_class::VoiceNotAllowed
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'creates object instance when voice param is a symbol' do
|
|
14
|
+
expect(described_class.new(:alyss)).to be_instance_of Voice
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'creates object instance when voice param is a string' do
|
|
18
|
+
expect(described_class.new('ALYSs')).to be_instance_of Voice
|
|
19
|
+
end
|
|
20
|
+
end # context #new
|
|
21
|
+
|
|
22
|
+
context '#list' do
|
|
23
|
+
it 'shows list of allowed voices' do
|
|
24
|
+
expect(described_class.list).to_not be_nil
|
|
25
|
+
end
|
|
26
|
+
end # context #list
|
|
27
|
+
end # describe Voice
|
|
28
|
+
end # module YandexSpeechApi
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module YandexSpeechApi
|
|
6
|
+
describe YandexSpeechApi do
|
|
7
|
+
context "Going to be tested with successful Net:HTTP requests" do
|
|
8
|
+
STUBBED_PATH = File.join __dir__, 'stubbed'
|
|
9
|
+
TEMP_PATH = File.join __dir__, 'tmp'
|
|
10
|
+
|
|
11
|
+
before :each do # stub Net:HTTP request
|
|
12
|
+
path = File.join(STUBBED_PATH, "stubbed_cat.mp3")
|
|
13
|
+
stub_request(:get, /https:\/\/tts.voicetech.yandex.net\/.*/)
|
|
14
|
+
.to_return status: 200, body: File.open(path).read
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
after :each do # clean-up tmp folder
|
|
18
|
+
Pathname.new(TEMP_PATH).children.reject { |c| c.basename.to_s == '.gitkeep' }
|
|
19
|
+
.each(&:unlink)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "Speaker#save_to_file" do
|
|
23
|
+
it 'saves audio-file' do
|
|
24
|
+
speaker = Speaker.init key: "xxxxx-xxxxx-xxxxx-xxxxx"
|
|
25
|
+
|
|
26
|
+
path = speaker.save_to_file("Не будите спящего кота.",
|
|
27
|
+
"spec/tmp/not_today")
|
|
28
|
+
|
|
29
|
+
expect(File.exist?(path)).to be_truthy
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'works fine when global key is set' do
|
|
33
|
+
Key.global_key = "xxxxx-xxxxx-xxxxx-xxxxx"
|
|
34
|
+
|
|
35
|
+
bobby = Speaker.init
|
|
36
|
+
path_to_bob_file =
|
|
37
|
+
bobby.save_to_file "Не будите спящего кота.", "spec/tmp/bobby"
|
|
38
|
+
|
|
39
|
+
expect(File.exist?(path_to_bob_file)).to be_truthy
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'works fine when filename not set' do
|
|
43
|
+
expect_any_instance_of(Speaker).to receive(:generate_path)
|
|
44
|
+
.and_return(File.join(TEMP_PATH, "bobby.mp3"))
|
|
45
|
+
|
|
46
|
+
bobby = Speaker.init(key: "xxxx")
|
|
47
|
+
path_to_bob_file = bobby.save_to_file "Не будите спящего кота."
|
|
48
|
+
|
|
49
|
+
expect(File.exist?(path_to_bob_file)).to be_truthy
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'sets correct params for object when block syntax is used' do
|
|
53
|
+
jane = Speaker.init do |j|
|
|
54
|
+
j.voice = :jane
|
|
55
|
+
j.language = :english
|
|
56
|
+
j.speed = :slow
|
|
57
|
+
j.emotion = :good
|
|
58
|
+
j.format = :opus
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
expect(jane.voice.name).to be_eql :jane
|
|
62
|
+
expect(jane.language.code).to be_eql 'en-US'
|
|
63
|
+
expect(jane.speed.value).to be_eql 0.5
|
|
64
|
+
expect(jane.emotion.type).to be_eql :good
|
|
65
|
+
expect(jane.format.type).to be_eql :opus
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'sets correct params for object when hash syntax is used' do
|
|
69
|
+
jane = Speaker.init(voice: :jane, language: :english,
|
|
70
|
+
speed: :slow, emotion: :good)
|
|
71
|
+
|
|
72
|
+
expect(jane.voice.name).to be_eql :jane
|
|
73
|
+
expect(jane.language.code).to be_eql 'en-US'
|
|
74
|
+
expect(jane.speed.value).to be_eql 0.5
|
|
75
|
+
expect(jane.emotion.type).to be_eql :good
|
|
76
|
+
end
|
|
77
|
+
end # context "Speaker#save_to_file"
|
|
78
|
+
|
|
79
|
+
# ----------------------------------------------------
|
|
80
|
+
|
|
81
|
+
context "Speaker#say" do
|
|
82
|
+
it 'calls mp3 player' do
|
|
83
|
+
expect_any_instance_of(MP3_Player::Base).to receive(:play)
|
|
84
|
+
|
|
85
|
+
speaker = Speaker.init key: "xxxxx-xxxxx-xxxxx-xxxxx"
|
|
86
|
+
speaker.say("Не будите спящего кота.")
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'raises an exception when text too long' do
|
|
90
|
+
speaker = Speaker.init key: "xxxxx-xxxxx-xxxxx-xxxxx"
|
|
91
|
+
phrase = 'some phrase' * 5000
|
|
92
|
+
|
|
93
|
+
expect{ speaker.say phrase }.to raise_exception Speaker::TextTooBig
|
|
94
|
+
end
|
|
95
|
+
end # context "Speaker#save_to_file"
|
|
96
|
+
end # context "Going to be tested with successful Net:HTTP requests"
|
|
97
|
+
|
|
98
|
+
# ----------------------------------------------------
|
|
99
|
+
|
|
100
|
+
context 'Going to be tested with failed Net:HTTP requests' do
|
|
101
|
+
it 'raises exception when connection falls' do
|
|
102
|
+
stub_request(:get, /https:\/\/tts.voicetech.yandex.net\/.*/)
|
|
103
|
+
.to_return status: 400, body: "Unreachable body"
|
|
104
|
+
|
|
105
|
+
bobby = Speaker.init key: "xxxxx-xxxxx-xxxxx-xxxxx"
|
|
106
|
+
|
|
107
|
+
expect{bobby.say "313"}
|
|
108
|
+
.to raise_exception Connection::ConnectionError
|
|
109
|
+
end
|
|
110
|
+
end # context "Going to be tested with failed Net:HTTP requests"
|
|
111
|
+
end # describe YandexSpeechApi
|
|
112
|
+
end # module YandexSpeechApi
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: yandex_speech_api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Kuzichev Michael
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: 'Text to speech translation. Supports next languages: english, turkey,
|
|
14
|
+
ukrain, russian. Supports speaker, emotion, speech speed selection. Based on Yandex
|
|
15
|
+
Speech API (about technology: https://tech.yandex.ru/speechkit/).'
|
|
16
|
+
email: kMedvedu@gmail.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- Gemfile
|
|
22
|
+
- LICENSE
|
|
23
|
+
- README.md
|
|
24
|
+
- lib/yandex_speech.rb
|
|
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
|
+
- lib/yandex_speech/mp3_player/base.rb
|
|
33
|
+
- lib/yandex_speech/mp3_player/linux_mp3_player.rb
|
|
34
|
+
- lib/yandex_speech/mp3_player/mac_mp3_player.rb
|
|
35
|
+
- lib/yandex_speech/project_structure.rb
|
|
36
|
+
- lib/yandex_speech/speaker.rb
|
|
37
|
+
- lib/yandex_speech/speed.rb
|
|
38
|
+
- lib/yandex_speech/voice.rb
|
|
39
|
+
- spec/spec_helper.rb
|
|
40
|
+
- spec/yandex_speech/connection_spec.rb
|
|
41
|
+
- spec/yandex_speech/emotion_spec.rb
|
|
42
|
+
- spec/yandex_speech/format_spec.rb
|
|
43
|
+
- spec/yandex_speech/helpers_spec.rb
|
|
44
|
+
- spec/yandex_speech/key_spec.rb
|
|
45
|
+
- spec/yandex_speech/language_spec.rb
|
|
46
|
+
- spec/yandex_speech/mp3_player/base_spec.rb
|
|
47
|
+
- 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
|
+
- spec/yandex_speech_spec.rb
|
|
52
|
+
homepage: https://github.com/Medvedu/Yandex-Speech-API
|
|
53
|
+
licenses:
|
|
54
|
+
- MIT
|
|
55
|
+
metadata: {}
|
|
56
|
+
post_install_message:
|
|
57
|
+
rdoc_options: []
|
|
58
|
+
require_paths:
|
|
59
|
+
- lib
|
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '2.0'
|
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
requirements:
|
|
71
|
+
- mpg123
|
|
72
|
+
rubyforge_project:
|
|
73
|
+
rubygems_version: 2.5.1
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 4
|
|
76
|
+
summary: Text to speech translation
|
|
77
|
+
test_files:
|
|
78
|
+
- spec/yandex_speech/language_spec.rb
|
|
79
|
+
- spec/yandex_speech/connection_spec.rb
|
|
80
|
+
- spec/yandex_speech/key_spec.rb
|
|
81
|
+
- spec/yandex_speech/helpers_spec.rb
|
|
82
|
+
- spec/yandex_speech/mp3_player/linux_mp3_player_spec.rb
|
|
83
|
+
- 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
|
+
- spec/spec_helper.rb
|
|
90
|
+
- spec/yandex_speech_spec.rb
|