rb-edge-tts 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 55add763b62d9ac29318185e9ab86a0f2fa34dbb7923710b033127e5a391f2b7
4
+ data.tar.gz: 709b647bf243f7c51be6412e8449bda7a25d2087ab360c67b02033d74b47f725
5
+ SHA512:
6
+ metadata.gz: 83792252d3b5556e06169d2501e0f72d2abed2e7590e802621d3fac450726bfadd289c890d878f2837cc676253a48ea7e01df665eef9a565dc27dfa2f4d0ae5c
7
+ data.tar.gz: 0a6204026e6dcbb5a3a7174f79cc304f81b5356b0ded366a41efe00dae347f15a59cc25243a9924fb42ea4331c75eaee0ed5d7669d80fdc410329b692fe7a81a
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec', '~> 3.12'
10
+ gem 'rubocop', '~> 1.50'
11
+ gem 'rubocop-rspec', '~> 2.20'
12
+ gem 'simplecov', '~> 0.22'
13
+ end
14
+
15
+ group :development, :test do
16
+ gem 'debug', '~> 1.8'
17
+ end
data/LICENSE ADDED
@@ -0,0 +1,195 @@
1
+ The MIT license is used for 'src/edge_tts/srt_composer.py' only. All
2
+ remaining files are licensed under the LGPLv3.
3
+
4
+ -----------------------------------------------------------------------
5
+
6
+ The MIT License
7
+
8
+ Copyright (c) 2014-2023 Christopher Down
9
+ Copyright (c) 2025- rany <rany@riseup.net>
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in
19
+ all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
+ THE SOFTWARE.
28
+
29
+ -----------------------------------------------------------------------
30
+
31
+ GNU LESSER GENERAL PUBLIC LICENSE
32
+ Version 3, 29 June 2007
33
+
34
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
35
+ Everyone is permitted to copy and distribute verbatim copies
36
+ of this license document, but changing it is not allowed.
37
+
38
+
39
+ This version of the GNU Lesser General Public License incorporates
40
+ the terms and conditions of version 3 of the GNU General Public
41
+ License, supplemented by the additional permissions listed below.
42
+
43
+ 0. Additional Definitions.
44
+
45
+ As used herein, "this License" refers to version 3 of the GNU Lesser
46
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
47
+ General Public License.
48
+
49
+ "The Library" refers to a covered work governed by this License,
50
+ other than an Application or a Combined Work as defined below.
51
+
52
+ An "Application" is any work that makes use of an interface provided
53
+ by the Library, but which is not otherwise based on the Library.
54
+ Defining a subclass of a class defined by the Library is deemed a mode
55
+ of using an interface provided by the Library.
56
+
57
+ A "Combined Work" is a work produced by combining or linking an
58
+ Application with the Library. The particular version of the Library
59
+ with which the Combined Work was made is also called the "Linked
60
+ Version".
61
+
62
+ The "Minimal Corresponding Source" for a Combined Work means the
63
+ Corresponding Source for the Combined Work, excluding any source code
64
+ for portions of the Combined Work that, considered in isolation, are
65
+ based on the Application, and not on the Linked Version.
66
+
67
+ The "Corresponding Application Code" for a Combined Work means the
68
+ object code and/or source code for the Application, including any data
69
+ and utility programs needed for reproducing the Combined Work from the
70
+ Application, but excluding the System Libraries of the Combined Work.
71
+
72
+ 1. Exception to Section 3 of the GNU GPL.
73
+
74
+ You may convey a covered work under sections 3 and 4 of this License
75
+ without being bound by section 3 of the GNU GPL.
76
+
77
+ 2. Conveying Modified Versions.
78
+
79
+ If you modify a copy of the Library, and, in your modifications, a
80
+ facility refers to a function or data to be supplied by an Application
81
+ that uses the facility (other than as an argument passed when the
82
+ facility is invoked), then you may convey a copy of the modified
83
+ version:
84
+
85
+ a) under this License, provided that you make a good faith effort to
86
+ ensure that, in the event an Application does not supply the
87
+ function or data, the facility still operates, and performs
88
+ whatever part of its purpose remains meaningful, or
89
+
90
+ b) under the GNU GPL, with none of the additional permissions of
91
+ this License applicable to that copy.
92
+
93
+ 3. Object Code Incorporating Material from Library Header Files.
94
+
95
+ The object code form of an Application may incorporate material from
96
+ a header file that is part of the Library. You may convey such object
97
+ code under terms of your choice, provided that, if the incorporated
98
+ material is not limited to numerical parameters, data structure
99
+ layouts and accessors, or small macros, inline functions and templates
100
+ (ten or fewer lines in length), you do both of the following:
101
+
102
+ a) Give prominent notice with each copy of the object code that the
103
+ Library is used in it and that the Library and its use are
104
+ covered by this License.
105
+
106
+ b) Accompany the object code with a copy of the GNU GPL and this license
107
+ document.
108
+
109
+ 4. Combined Works.
110
+
111
+ You may convey a Combined Work under terms of your choice that,
112
+ taken together, effectively do not restrict modification of the
113
+ portions of the Library contained in the Combined Work and reverse
114
+ engineering for debugging such modifications, if you also do each of
115
+ the following:
116
+
117
+ a) Give prominent notice with each copy of the Combined Work that
118
+ the Library is used in it and that the Library and its use are
119
+ covered by this License.
120
+
121
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
122
+ document.
123
+
124
+ c) For a Combined Work that displays copyright notices during
125
+ execution, include the copyright notice for the Library among
126
+ these notices, as well as a reference directing the user to the
127
+ copies of the GNU GPL and this license document.
128
+
129
+ d) Do one of the following:
130
+
131
+ 0) Convey the Minimal Corresponding Source under the terms of this
132
+ License, and the Corresponding Application Code in a form
133
+ suitable for, and under terms that permit, the user to
134
+ recombine or relink the Application with a modified version of
135
+ the Linked Version to produce a modified Combined Work, in the
136
+ manner specified by section 6 of the GNU GPL for conveying
137
+ Corresponding Source.
138
+
139
+ 1) Use a suitable shared library mechanism for linking with the
140
+ Library. A suitable mechanism is one that (a) uses at run time
141
+ a copy of the Library already present on the user's computer
142
+ system, and (b) will operate properly with a modified version
143
+ of the Library that is interface-compatible with the Linked
144
+ Version.
145
+
146
+ e) Provide Installation Information, but only if you would otherwise
147
+ be required to provide such information under section 6 of the
148
+ GNU GPL, and only to the extent that such information is
149
+ necessary to install and execute a modified version of the
150
+ Combined Work produced by recombining or relinking the
151
+ Application with a modified version of the Linked Version. (If
152
+ you use option 4d0, the Installation Information must accompany
153
+ the Minimal Corresponding Source and Corresponding Application
154
+ Code. If you use option 4d1, you must provide the Installation
155
+ Information in the manner specified by section 6 of the GNU GPL
156
+ for conveying Corresponding Source.)
157
+
158
+ 5. Combined Libraries.
159
+
160
+ You may place library facilities that are a work based on the
161
+ Library side by side in a single library together with other library
162
+ facilities that are not Applications and are not covered by this
163
+ License, and convey such a combined library under terms of your
164
+ choice, if you do both of the following:
165
+
166
+ a) Accompany the combined library with a copy of the same work based
167
+ on the Library, uncombined with any other library facilities,
168
+ conveyed under the terms of this License.
169
+
170
+ b) Give prominent notice with the combined library that part of it
171
+ is a work based on the Library, and explaining where to find the
172
+ accompanying uncombined form of the same work.
173
+
174
+ 6. Revised Versions of the GNU Lesser General Public License.
175
+
176
+ The Free Software Foundation may publish revised and/or new versions
177
+ of the GNU Lesser General Public License from time to time. Such new
178
+ versions will be similar in spirit to the present version, but may
179
+ differ in detail to address new problems or concerns.
180
+
181
+ Each version is given a distinguishing version number. If the
182
+ Library as you received it specifies that a certain numbered version
183
+ of the GNU Lesser General Public License "or any later version"
184
+ applies to it, you have the option of following the terms and
185
+ conditions either of that published version or of any later version
186
+ published by the Free Software Foundation. If the Library as you
187
+ received it does not specify a version number of the GNU Lesser
188
+ General Public License, you may choose any version of the GNU Lesser
189
+ General Public License ever published by the Free Software Foundation.
190
+
191
+ If the Library as you received it specifies that a proxy can decide
192
+ whether future versions of the GNU Lesser General Public License shall
193
+ apply, that proxy's public statement of acceptance of any version is
194
+ permanent authorization for you to choose that version for the
195
+ Library.
data/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # rb-edge-tts
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rb-edge-tts.svg)](https://badge.fury.io/rb/rb-edge-tts)
4
+ [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
5
+
6
+ Microsoft Edge Online Text-to-Speech Service (Ruby Gem).
7
+
8
+ This is a Ruby implementation of the Microsoft Edge Online Text-to-Speech (TTS) service. It provides a simple and easy-to-use interface, allowing you to use high-quality Edge TTS voices directly within your Ruby applications or via the command line.
9
+
10
+ This project is a port of the Python project [edge-tts](https://github.com/rany2/edge-tts).
11
+
12
+ ## Features
13
+
14
+ - **High-Quality Voices**: Direct access to Microsoft Edge's online neural voices.
15
+ - **Multi-Language Support**: Supports 100+ languages and 400+ voices.
16
+ - **Highly Customizable**: Adjustable rate, volume, and pitch.
17
+ - **Subtitle Generation**: Supports generating subtitles in SRT format.
18
+ - **Command-Line Tools**: Includes `rb-edge-tts` and `rb-edge-playback` CLI tools.
19
+ - **Lightweight**: Removed unnecessary async dependencies, using standard Ruby libraries and efficient WebSocket handling.
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'rb-edge-tts'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ ```bash
32
+ $ bundle install
33
+ ```
34
+
35
+ Or install it yourself as:
36
+
37
+ ```bash
38
+ $ gem install rb-edge-tts
39
+ ```
40
+
41
+ ## Quick Start
42
+
43
+ ### Command Line Usage
44
+
45
+ `rb-edge-tts` provides a powerful command-line interface.
46
+
47
+ **Basic Usage: Generate MP3**
48
+
49
+ ```bash
50
+ $ rb-edge-tts --text 'Hello, world!' --write-media hello.mp3
51
+ ```
52
+
53
+ **Generate Audio and Subtitles**
54
+
55
+ ```bash
56
+ $ rb-edge-tts --text 'Hello, world!' --write-media hello.mp3 --write-subtitles hello.srt
57
+ ```
58
+
59
+ **Use a Specific Voice**
60
+
61
+ ```bash
62
+ $ rb-edge-tts --text 'Hello, world!' --voice en-GB-SoniaNeural --write-media hello.mp3
63
+ $ rb-edge-tts -f test.txt --write-media test.mp3 -v de-DE-AmalaNeural
64
+ ```
65
+
66
+ **Adjust Parameters (Rate, Volume, Pitch)**
67
+
68
+ ```bash
69
+ $ rb-edge-tts --rate=+20% --volume=+10% --pitch=+5Hz --text 'Hello, world!' --write-media output.mp3
70
+ ```
71
+
72
+ **Instant Playback**
73
+
74
+ Use the `rb-edge-playback` command to play the generated speech immediately (requires `mpv` installed):
75
+
76
+ ```bash
77
+ $ rb-edge-playback --text 'Hello, world!'
78
+ ```
79
+
80
+ **List All Available Voices**
81
+
82
+ ```bash
83
+ $ rb-edge-tts --list-voices
84
+ ```
85
+
86
+ ### Ruby Library Usage
87
+
88
+ **Basic Example**
89
+
90
+ ```ruby
91
+ require 'rb_edge_tts'
92
+
93
+ # Use default voice
94
+ communicate = RbEdgeTTS::Communicate.new('Hello, world!')
95
+ communicate.save("output.mp3")
96
+ ```
97
+
98
+ **Advanced Example: Custom Parameters**
99
+
100
+ ```ruby
101
+ require 'rb_edge_tts'
102
+
103
+ communicate = RbEdgeTTS::Communicate.new(
104
+ 'Hello, world!',
105
+ "en-US-AriaNeural",
106
+ rate: "+10%", # Speed
107
+ volume: "+20%", # Volume
108
+ pitch: "+5Hz" # Pitch
109
+ )
110
+ communicate.save("output.mp3")
111
+ ```
112
+
113
+ **Generating Subtitles**
114
+
115
+ ```ruby
116
+ require 'rb_edge_tts'
117
+
118
+ communicate = RbEdgeTTS::Communicate.new('Hello, world!')
119
+ submaker = RbEdgeTTS::SubMaker.new
120
+
121
+ File.open("output.mp3", "wb") do |file|
122
+ communicate.stream do |chunk|
123
+ if chunk.type == "audio"
124
+ file.write(chunk.data)
125
+ elsif %w[WordBoundary SentenceBoundary].include?(chunk.type)
126
+ submaker.feed(chunk)
127
+ end
128
+ end
129
+ end
130
+
131
+ File.write("output.srt", submaker.to_srt)
132
+ ```
133
+
134
+ **Streaming**
135
+
136
+ ```ruby
137
+ require 'rb_edge_tts'
138
+
139
+ communicate = RbEdgeTTS::Communicate.new('Hello, world!')
140
+
141
+ communicate.stream do |chunk|
142
+ if chunk.type == "audio"
143
+ # Process audio data chunk (chunk.data)
144
+ print "."
145
+ end
146
+ end
147
+ ```
148
+
149
+ ## Voice Management
150
+
151
+ You can use `VoicesManager` to find and filter available voices.
152
+
153
+ ```ruby
154
+ require 'rb_edge_tts'
155
+
156
+ # Get all available voices
157
+ voices = RbEdgeTTS::VoicesManager.create
158
+
159
+ # Find all Chinese (Simplified) Female voices
160
+ chinese_female_voices = voices.find(locale: "zh-CN", gender: "Female")
161
+
162
+ chinese_female_voices.each do |voice|
163
+ puts "#{voice.short_name}: #{voice.friendly_name}"
164
+ end
165
+ ```
166
+
167
+ ## Development Guide
168
+
169
+ This section is for developers who want to contribute to `rb-edge-tts` or build from source.
170
+
171
+ ### Requirements
172
+
173
+ - Ruby 3.0 or higher
174
+
175
+ ### Local Setup
176
+
177
+ 1. **Clone the repository**
178
+
179
+ ```bash
180
+ git clone https://github.com/ZPVIP/rb-edge-tts.git
181
+ cd rb-edge-tts
182
+ ```
183
+
184
+ 2. **Install dependencies**
185
+
186
+ ```bash
187
+ bundle install
188
+ ```
189
+
190
+ 3. **Run tests**
191
+
192
+ We use `rspec` for testing.
193
+
194
+ ```bash
195
+ bundle exec rspec
196
+ ```
197
+
198
+ ### Local Build and Install
199
+
200
+ If you modified the code and want to test it locally:
201
+
202
+ 1. **Build the Gem**
203
+
204
+ ```bash
205
+ gem build rb-edge-tts.gemspec
206
+ ```
207
+
208
+ This will generate an `rb-edge-tts-<version>.gem` file.
209
+
210
+ 2. **Install the Gem**
211
+
212
+ ```bash
213
+ gem install ./rb-edge-tts-<version>.gem
214
+ ```
215
+
216
+ 3. **Verify Installation**
217
+
218
+ ```bash
219
+ rb-edge-tts --version
220
+ ```
221
+
222
+ ### Publishing
223
+
224
+ To publish a new version to RubyGems (requires permissions):
225
+
226
+ 1. Update the version number in `lib/rb_edge_tts/version.rb`.
227
+ 2. Update `CHANGELOG.md`.
228
+ 3. Build and push:
229
+
230
+ ```bash
231
+ gem build rb-edge-tts.gemspec
232
+ gem push rb-edge-tts-<version>.gem
233
+ ```
234
+
235
+ ## Dependencies
236
+
237
+ - `eventmachine`: For WebSocket event loop.
238
+ - `faye-websocket`: WebSocket client implementation.
239
+ - `json`: JSON data processing.
240
+ - `terminal-table`: For formatting CLI output.
241
+ - `net/http`: For fetching voice lists (Standard Library).
242
+
243
+ ## License
244
+
245
+ This project is licensed under the [GNU Lesser General Public License v3.0 (LGPLv3)](LICENSE).
246
+
247
+ The `lib/rb_edge_tts/srt_composer.rb` file is licensed under the MIT License.
248
+
249
+ ## Acknowledgments
250
+
251
+ This project is a Ruby port of the Python project [edge-tts](https://github.com/rany2/edge-tts). Thanks to [rany2](https://github.com/rany2) for developing the original version, making high-quality TTS conversion possible via the Edge interface.
252
+
253
+ For questions regarding Python implementation details, please refer to the original project.
254
+
255
+ ---
256
+
257
+ [Fork on GitHub](https://github.com/zpvip/rb-edge-tts) | [Report an Issue](https://github.com/zpvip/rb-edge-tts/issues)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rb_edge_tts'
5
+ require 'async'
6
+
7
+ TEXT = 'Hoy es un buen día.'
8
+ OUTPUT_FILE = 'spanish.mp3'
9
+
10
+ Async do
11
+ voices = RbEdgeTTS::VoicesManager.create
12
+ voice = voices.find(locale: 'es', gender: 'Male')
13
+
14
+ if voice.empty?
15
+ puts 'No male Spanish voice found'
16
+ exit 1
17
+ end
18
+
19
+ selected_voice = voice.sample
20
+ puts "Using voice: #{selected_voice.name}"
21
+
22
+ communicate = RbEdgeTTS::Communicate.new(TEXT, selected_voice.name)
23
+ communicate.save(OUTPUT_FILE)
24
+
25
+ puts "Audio saved to #{OUTPUT_FILE}"
26
+ end.wait
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rb_edge_tts'
5
+
6
+ TEXT = 'Hello World!'
7
+ VOICE = 'en-GB-SoniaNeural'
8
+ OUTPUT_FILE = 'test.mp3'
9
+
10
+ communicate = RbEdgeTTS::Communicate.new(TEXT, VOICE)
11
+ communicate.save(OUTPUT_FILE)
12
+
13
+ puts "Audio saved to #{OUTPUT_FILE}"
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rb_edge_tts'
5
+ require 'async'
6
+
7
+ TEXT = 'Hello World!'
8
+ VOICE = 'en-GB-SoniaNeural'
9
+ OUTPUT_FILE = 'test.mp3'
10
+
11
+ Async do
12
+ communicate = RbEdgeTTS::Communicate.new(TEXT, VOICE)
13
+ communicate.save(OUTPUT_FILE)
14
+
15
+ puts "Audio saved to #{OUTPUT_FILE}"
16
+ end.wait
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rb_edge_tts'
5
+ require 'async'
6
+
7
+ TEXT = 'Hello World!'
8
+ VOICE = 'en-GB-SoniaNeural'
9
+ OUTPUT_FILE = 'test.mp3'
10
+ SRT_FILE = 'test.srt'
11
+
12
+ Async do
13
+ communicate = RbEdgeTTS::Communicate.new(TEXT, VOICE)
14
+ submaker = RbEdgeTTS::SubMaker.new
15
+
16
+ File.open(OUTPUT_FILE, 'wb') do |file|
17
+ communicate.stream do |chunk|
18
+ if chunk.type == 'audio'
19
+ file.write(chunk.data)
20
+ elsif %w[WordBoundary SentenceBoundary].include?(chunk.type)
21
+ submaker.feed(chunk)
22
+ end
23
+ end
24
+ end
25
+
26
+ File.write(SRT_FILE, submaker.get_srt)
27
+
28
+ puts "Audio saved to #{OUTPUT_FILE}"
29
+ puts "Subtitles saved to #{SRT_FILE}"
30
+ end.wait