voicemaker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +173 -0
- data/bin/voicemaker +25 -0
- data/lib/sample.yml +11 -0
- data/lib/voicemaker/api.rb +66 -0
- data/lib/voicemaker/cli.rb +10 -0
- data/lib/voicemaker/command.rb +111 -0
- data/lib/voicemaker/exceptions.rb +6 -0
- data/lib/voicemaker/version.rb +3 -0
- data/lib/voicemaker.rb +5 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 84b3811f8d8ef6084933654f41b1764c2e1c3eb1d59ac8a6e599d1c18a38bd7a
|
4
|
+
data.tar.gz: 91491d408b0884424c20771d4a4b9d230a7cd29dc05eb7d4f55caeb2ca8e5440
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98939ba36fb37cc71987060376422da98e064fab61074f08d8f853d5ce35a1f648db32d10ea7da5c25b9af67c908b4b901fff3b35244dfb96ee9b5d3b795e717
|
7
|
+
data.tar.gz: 1d4a1894a2f1eddbd30b93bb5c1226664079daaaba8c5f72510a6a5912efb65ad49e1b270a1ee628ce6b4e197285af59f5bcb65da3e70b7b2f2c3c0a4b7b5b84
|
data/README.md
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
# Voicemaker API Library and Command Line
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/voicemaker.svg)](https://badge.fury.io/rb/voicemaker)
|
4
|
+
[![Build Status](https://github.com/DannyBen/voicemaker/workflows/Test/badge.svg)](https://github.com/DannyBen/voicemaker/actions?query=workflow%3ATest)
|
5
|
+
|
6
|
+
---
|
7
|
+
|
8
|
+
This gem provides both a Ruby library and a command line interface for the
|
9
|
+
[Voicemaker][voicemaker] Text to Speech service.
|
10
|
+
|
11
|
+
This gem is not affiliated with Voicemaker.
|
12
|
+
|
13
|
+
---
|
14
|
+
|
15
|
+
|
16
|
+
## Install
|
17
|
+
|
18
|
+
```
|
19
|
+
$ gem install voicemaker
|
20
|
+
```
|
21
|
+
|
22
|
+
## Features
|
23
|
+
|
24
|
+
- Use as a Ruby library or from the command line
|
25
|
+
- Show and search for available voices
|
26
|
+
- Convert text to MP3 or WAV from a simple configuration file
|
27
|
+
- Batch-convert multiple files
|
28
|
+
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
### Initialization
|
33
|
+
|
34
|
+
First, require and initialize with your Voicemaker API key:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'voicemaker'
|
38
|
+
api_key = '...'
|
39
|
+
api = Voicemaker::API.new api_key
|
40
|
+
```
|
41
|
+
|
42
|
+
### Voices list
|
43
|
+
|
44
|
+
Get the full voices list:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
result = api.voices
|
48
|
+
```
|
49
|
+
|
50
|
+
Search the voices list for one or more strings (AND search):
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
result = api.voices ["en_US", "female"]
|
54
|
+
```
|
55
|
+
|
56
|
+
### Audio generation and download
|
57
|
+
|
58
|
+
Make an API call and get the URL to the audio file in return:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
params = {
|
62
|
+
"Engine" => "neural",
|
63
|
+
"VoiceId" => "ai3-Jony",
|
64
|
+
"LanguageCode" => "en-US",
|
65
|
+
"OutputFormat" => "mp3",
|
66
|
+
"SampleRate" => "48000",
|
67
|
+
"Effect" => "default",
|
68
|
+
"MasterSpeed" => "0",
|
69
|
+
"MasterVolume" => "0",
|
70
|
+
"MasterPitch" => "0",
|
71
|
+
"Text" => "Hello world",
|
72
|
+
}
|
73
|
+
|
74
|
+
result = api.generate params
|
75
|
+
```
|
76
|
+
|
77
|
+
For convenience, you can call `#download` instead, to mak ethe API call and
|
78
|
+
download the file:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
result = api.download "out.mp3', params
|
82
|
+
```
|
83
|
+
|
84
|
+
## Command line interface
|
85
|
+
|
86
|
+
<!-- USAGE -->
|
87
|
+
```
|
88
|
+
$ voicemaker --help
|
89
|
+
|
90
|
+
Voicemaker API
|
91
|
+
|
92
|
+
API Documentation:
|
93
|
+
https://developer.voicemaker.in/apidocs
|
94
|
+
|
95
|
+
Usage:
|
96
|
+
voicemaker voices [--save PATH] [SEARCH...]
|
97
|
+
voicemaker new CONFIG
|
98
|
+
voicemaker generate CONFIG [OUTPUT]
|
99
|
+
voicemaker batch INDIR OUTDIR
|
100
|
+
voicemaker (-h|--help|--version)
|
101
|
+
|
102
|
+
Commands:
|
103
|
+
voices
|
104
|
+
Get list of voices, optionally in a given language
|
105
|
+
|
106
|
+
new
|
107
|
+
Generate a sample config file
|
108
|
+
|
109
|
+
generate
|
110
|
+
Generate audio file. The output filename will be the same as the config
|
111
|
+
filename, with the proper mp3 or wav extension
|
112
|
+
|
113
|
+
batch
|
114
|
+
Generate multiple audio files from multiple config files
|
115
|
+
|
116
|
+
Options:
|
117
|
+
-l --language LANG
|
118
|
+
Limit results to a specific language
|
119
|
+
|
120
|
+
-s --save PATH
|
121
|
+
Save output to output YAML file
|
122
|
+
|
123
|
+
-h --help
|
124
|
+
Show this help
|
125
|
+
|
126
|
+
--version
|
127
|
+
Show version number
|
128
|
+
|
129
|
+
Parameters:
|
130
|
+
SEARCH
|
131
|
+
Provide one or more text strings to search for (case insensitive)
|
132
|
+
|
133
|
+
CONFIG
|
134
|
+
Path to config file
|
135
|
+
|
136
|
+
OUTPUT
|
137
|
+
Path to output mp3/wav file. If not provided, the filename will be the same
|
138
|
+
as the config file, with wav/mp3 extension
|
139
|
+
|
140
|
+
INDIR
|
141
|
+
Path to input directory, containing config YAML files
|
142
|
+
|
143
|
+
OURDIR
|
144
|
+
Path to output directory, where mp3/wav files will be saved
|
145
|
+
|
146
|
+
Environment Variables:
|
147
|
+
VOICEMAKER_API_KEY
|
148
|
+
Your Voicemaker API key [required]
|
149
|
+
|
150
|
+
VOICEMAKER_API_HOST
|
151
|
+
Override the API host URL
|
152
|
+
|
153
|
+
Examples:
|
154
|
+
voicemaker voices en-us
|
155
|
+
voicemaker voices --save out.yml en-us
|
156
|
+
voicemaker voices en-us female
|
157
|
+
voicemaker new test.yml
|
158
|
+
voicemaker generate test.yml out.mp3
|
159
|
+
voicemaker batch configs out
|
160
|
+
|
161
|
+
```
|
162
|
+
<!-- USAGE -->
|
163
|
+
|
164
|
+
|
165
|
+
## Contributing / Support
|
166
|
+
|
167
|
+
If you experience any issue, have a question or a suggestion, or if you wish
|
168
|
+
to contribute, feel free to [open an issue][issues].
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
[voicemaker]: https://voicemaker.in/
|
173
|
+
[issues]: https://github.com/DannyBen/voicemaker/issues
|
data/bin/voicemaker
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'colsole'
|
3
|
+
require 'voicemaker'
|
4
|
+
require 'voicemaker/cli'
|
5
|
+
include Colsole
|
6
|
+
|
7
|
+
runner = Voicemaker::CLI.runner
|
8
|
+
|
9
|
+
begin
|
10
|
+
exit runner.run ARGV
|
11
|
+
|
12
|
+
rescue Interrupt
|
13
|
+
say "\nGoodbye"
|
14
|
+
exit 1
|
15
|
+
|
16
|
+
rescue => e
|
17
|
+
if ENV['DEBUG']
|
18
|
+
puts e.backtrace.reverse
|
19
|
+
say ""
|
20
|
+
end
|
21
|
+
say "!undred!ERROR: #{e.class}"
|
22
|
+
say e.message
|
23
|
+
exit 1
|
24
|
+
|
25
|
+
end
|
data/lib/sample.yml
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'down'
|
3
|
+
|
4
|
+
module Voicemaker
|
5
|
+
class API
|
6
|
+
attr_reader :api_key
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_writer :base_uri
|
10
|
+
|
11
|
+
def base_uri
|
12
|
+
@base_uri ||= ENV['VOICEMAKER_API_HOST'] || 'https://developer.voicemaker.in/voice'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(api_key)
|
17
|
+
@api_key = api_key
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a list of voices, with optional search criteria (array)
|
21
|
+
def voices(search = nil)
|
22
|
+
search = nil if search&.empty?
|
23
|
+
response = HTTP.auth(auth_header).get "#{base_uri}/list"
|
24
|
+
raise BadResponse, "#{response.status}\n#{response.body}" unless response.status.success?
|
25
|
+
voices = response.parse.dig 'data', 'voices_list'
|
26
|
+
raise BadResponse, "Unexpected response: #{response}" unless voices
|
27
|
+
|
28
|
+
if search
|
29
|
+
voices.select do |voice|
|
30
|
+
search_string = voice.values.join(' ').downcase
|
31
|
+
search.any? { |query| search_string.include? query.downcase }
|
32
|
+
end
|
33
|
+
else
|
34
|
+
voices
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the URL for the generated file
|
39
|
+
def generate(params = {})
|
40
|
+
response = HTTP.auth(auth_header).post "#{base_uri}/api", json: params
|
41
|
+
if response.status.success?
|
42
|
+
response.parse['path']
|
43
|
+
else
|
44
|
+
raise BadResponse, "#{response.status}\n#{response.body}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Calls the API and saves the file
|
49
|
+
def download(outpath, params = {})
|
50
|
+
path = generate params
|
51
|
+
yield path if block_given?
|
52
|
+
Down.download path, destination: outpath
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
def base_uri
|
58
|
+
self.class.base_uri
|
59
|
+
end
|
60
|
+
|
61
|
+
def auth_header
|
62
|
+
"Bearer #{api_key}"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'lp'
|
2
|
+
require 'mister_bin'
|
3
|
+
|
4
|
+
module Voicemaker
|
5
|
+
class Command < MisterBin::Command
|
6
|
+
help "Voicemaker API\n\n API Documentation:\n https://developer.voicemaker.in/apidocs"
|
7
|
+
version Voicemaker::VERSION
|
8
|
+
|
9
|
+
usage "voicemaker voices [--save PATH] [SEARCH...]"
|
10
|
+
usage "voicemaker new CONFIG"
|
11
|
+
usage "voicemaker generate CONFIG [OUTPUT]"
|
12
|
+
usage "voicemaker batch INDIR OUTDIR"
|
13
|
+
usage "voicemaker (-h|--help|--version)"
|
14
|
+
|
15
|
+
command "voices", "Get list of voices, optionally in a given language"
|
16
|
+
command "new", "Generate a sample config file"
|
17
|
+
command "generate", "Generate audio file. The output filename will be the same as the config filename, with the proper mp3 or wav extension"
|
18
|
+
command "batch", "Generate multiple audio files from multiple config files"
|
19
|
+
|
20
|
+
option "-l --language LANG", "Limit results to a specific language"
|
21
|
+
option "-s --save PATH", "Save output to output YAML file"
|
22
|
+
|
23
|
+
param "SEARCH", "Provide one or more text strings to search for (case insensitive)"
|
24
|
+
param "CONFIG", "Path to config file"
|
25
|
+
param "OUTPUT", "Path to output mp3/wav file. If not provided, the filename will be the same as the config file, with wav/mp3 extension"
|
26
|
+
param "INDIR", "Path to input directory, containing config YAML files"
|
27
|
+
param "OURDIR", "Path to output directory, where mp3/wav files will be saved"
|
28
|
+
|
29
|
+
environment "VOICEMAKER_API_KEY", "Your Voicemaker API key [required]"
|
30
|
+
environment "VOICEMAKER_API_HOST", "Override the API host URL"
|
31
|
+
|
32
|
+
example "voicemaker voices en-us"
|
33
|
+
example "voicemaker voices --save out.yml en-us"
|
34
|
+
example "voicemaker voices en-us female"
|
35
|
+
example "voicemaker new test.yml"
|
36
|
+
example "voicemaker generate test.yml out.mp3"
|
37
|
+
example "voicemaker batch configs out"
|
38
|
+
|
39
|
+
def voices_command
|
40
|
+
send_output api.voices(args['SEARCH'])
|
41
|
+
end
|
42
|
+
|
43
|
+
def new_command
|
44
|
+
template = File.expand_path "../sample.yml", __dir__
|
45
|
+
content = File.read template
|
46
|
+
File.write args['CONFIG'], content
|
47
|
+
say "Saved #{args['CONFIG']}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def generate_command
|
51
|
+
config_path = args['CONFIG']
|
52
|
+
raise InputError, "Cannot find config file #{config_path}" unless File.exist? config_path
|
53
|
+
outpath = args['OUTPUT'] || outpath_from_config(config_path)
|
54
|
+
generate config_path, outpath
|
55
|
+
end
|
56
|
+
|
57
|
+
def batch_command
|
58
|
+
files = Dir["#{args['INDIR']}/*.yml"].sort
|
59
|
+
raise InputError, "No config files in #{args['INDIR']}" if files.empty?
|
60
|
+
|
61
|
+
files.each do |config_path|
|
62
|
+
extension = extension_from_config(config_path)
|
63
|
+
basename = File.basename config_path, '.yml'
|
64
|
+
outpath = "#{args['OUTDIR']}/#{basename}.#{extension}"
|
65
|
+
generate config_path, outpath
|
66
|
+
puts ""
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def generate(config_path, outpath)
|
73
|
+
params = YAML.load_file config_path
|
74
|
+
|
75
|
+
say "Config : !txtgrn!#{config_path}"
|
76
|
+
api.download outpath, params do |url|
|
77
|
+
say "URL : !txtblu!#{url}"
|
78
|
+
end
|
79
|
+
|
80
|
+
say "Path : !txtblu!#{outpath}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def send_output(data)
|
84
|
+
save = args['--save']
|
85
|
+
if save
|
86
|
+
say "Saved #{save}"
|
87
|
+
File.write save, data.to_yaml
|
88
|
+
else
|
89
|
+
lp data
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def api
|
94
|
+
@api ||= Voicemaker::API.new(api_key)
|
95
|
+
end
|
96
|
+
|
97
|
+
def api_key
|
98
|
+
ENV['VOICEMAKER_API_KEY'] or raise MissingAuth, "Please set the 'VOICEMAKER_API_KEY' environment variable"
|
99
|
+
end
|
100
|
+
|
101
|
+
def outpath_from_config(config_path)
|
102
|
+
ext = extension_from_config config_path
|
103
|
+
config_path.gsub(/yml$/, ext)
|
104
|
+
end
|
105
|
+
|
106
|
+
def extension_from_config(config_path)
|
107
|
+
YAML.load_file(config_path)['OutputFormat']
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
data/lib/voicemaker.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voicemaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Ben Shitrit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mister_bin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: lp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: http
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: down
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.3'
|
69
|
+
description: Easy to use API for Voicemaker.in TTS service, with a command line interface
|
70
|
+
email: db@dannyben.com
|
71
|
+
executables:
|
72
|
+
- voicemaker
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- bin/voicemaker
|
78
|
+
- lib/sample.yml
|
79
|
+
- lib/voicemaker.rb
|
80
|
+
- lib/voicemaker/api.rb
|
81
|
+
- lib/voicemaker/cli.rb
|
82
|
+
- lib/voicemaker/command.rb
|
83
|
+
- lib/voicemaker/exceptions.rb
|
84
|
+
- lib/voicemaker/version.rb
|
85
|
+
homepage: https://github.com/DannyBen/voicemaker
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
bug_tracker_uri: https://github.com/DannyBen/voicemaker/issues
|
90
|
+
changelog_uri: https://github.com/DannyBen/voicemaker/blob/master/CHANGELOG.md
|
91
|
+
homepage_uri: https://github.com/DannyBen/voicemaker
|
92
|
+
source_code_uri: https://github.com/DannyBen/voicemaker
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.7.0
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubygems_version: 3.3.3
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Voicemaker.in Text to Speech API Library and Command Line
|
112
|
+
test_files: []
|