RubiSpeech 0.1.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 +7 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +9 -0
- data/Rakefile +8 -0
- data/Readme.md +152 -0
- data/examples/example-1.rb +76 -0
- data/lib/my_speech_library/os_detector.rb +39 -0
- data/lib/my_speech_library/speaker.rb +41 -0
- data/lib/my_speech_library/version.rb +5 -0
- data/lib/my_speech_library.rb +28 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 369299c826cd1d82dbb2c1787e38b184a4b19939b0aeaac47ef20d01ad1f1b3d
|
4
|
+
data.tar.gz: 5c311538e7123bc6a13125488d9e2219cabcea8c20bceaf30439a38b50ee14cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c130a500cb17a03cde4a9ea856f9414f712c0c81d8bd6272661f3f4a2ae7d8889217c767b6b09163ac3762701a20ca14181e498369aeece7d4f1a79de0a0541c
|
7
|
+
data.tar.gz: df9933b84c3917716cb0a625e98597ac57379e73b777d4b1060f1f40a41801117d98f812955ff08990d4fef6764497ae419d32e3621e312a8807ce9620fe4df3
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
# RubiSpeech
|
2
|
+
|
3
|
+
A lightweight, cross-platform Ruby gem for text-to-speech functionality. RubiSpeech is designed for AI applications and natural language processing systems, with the ability to detect and adapt to different operating systems (Windows, macOS, Linux).
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/RubiSpeech)
|
6
|
+
[](LICENSE)
|
7
|
+
|
8
|
+
## Features
|
9
|
+
|
10
|
+
- Cross-platform text-to-speech capabilities
|
11
|
+
- Automatic operating system detection
|
12
|
+
- Easy-to-use API
|
13
|
+
- Supports Windows, macOS, and Linux
|
14
|
+
- Designed for AI and NLP applications
|
15
|
+
|
16
|
+
## Requirements
|
17
|
+
|
18
|
+
- Ruby >= 2.6.0
|
19
|
+
- Windows: No additional requirements (uses System.Speech via PowerShell)
|
20
|
+
- macOS: No additional requirements (uses built-in `say` command)
|
21
|
+
- Linux: `espeak` package installed
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'RubiSpeech'
|
29
|
+
```
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
```
|
34
|
+
$ bundle install
|
35
|
+
```
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
```
|
40
|
+
$ gem install RubiSpeech
|
41
|
+
```
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
### Quick Start
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'my_speech_library'
|
49
|
+
|
50
|
+
# Simple usage - speak text immediately
|
51
|
+
MySpeechLibrary.talk("Hello, world!")
|
52
|
+
```
|
53
|
+
|
54
|
+
### Creating an Instance
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'my_speech_library'
|
58
|
+
|
59
|
+
# Create a speech instance
|
60
|
+
speech = MySpeechLibrary::Speech.new
|
61
|
+
|
62
|
+
# Speak some text
|
63
|
+
speech.talk("Hello, I'm speaking using RubiSpeech library")
|
64
|
+
|
65
|
+
# Check the current operating system
|
66
|
+
current_os = speech.current_os
|
67
|
+
puts "Current operating system: #{current_os}"
|
68
|
+
```
|
69
|
+
|
70
|
+
### Multiple Phrases with Interval
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
require 'my_speech_library'
|
74
|
+
|
75
|
+
# Create a new instance
|
76
|
+
speaker = MySpeechLibrary::Speech.new
|
77
|
+
|
78
|
+
# Phrases to speak
|
79
|
+
phrases = [
|
80
|
+
"Welcome to the Ruby world",
|
81
|
+
"This is a text-to-speech library",
|
82
|
+
"Works on Windows, Mac, and Linux"
|
83
|
+
]
|
84
|
+
|
85
|
+
# Speak each phrase with a time interval
|
86
|
+
phrases.each do |phrase|
|
87
|
+
speaker.talk(phrase)
|
88
|
+
sleep(2) # Wait for 2 seconds between phrases
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
### Direct Use of Components
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
require 'my_speech_library'
|
96
|
+
|
97
|
+
# Use the OS detector directly
|
98
|
+
os_detector = MySpeechLibrary::OSDetector.new
|
99
|
+
puts "Is the system Windows? #{os_detector.windows?}"
|
100
|
+
puts "Is the system macOS? #{os_detector.macos?}"
|
101
|
+
puts "Is the system Linux? #{os_detector.linux?}"
|
102
|
+
|
103
|
+
# Use the speaker directly
|
104
|
+
speaker = MySpeechLibrary::Speaker.new(os_detector)
|
105
|
+
speaker.speak("This is a test using the Speaker class directly")
|
106
|
+
```
|
107
|
+
|
108
|
+
### Simple Translation Application Example
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
require 'my_speech_library'
|
112
|
+
|
113
|
+
def translate_and_speak(text, language)
|
114
|
+
# This is a hypothetical translation example (in a real app, you'd need a translation service)
|
115
|
+
translated = case language
|
116
|
+
when :english
|
117
|
+
"This is translated to English: " + text
|
118
|
+
when :french
|
119
|
+
"C'est traduit en français: " + text
|
120
|
+
else
|
121
|
+
text
|
122
|
+
end
|
123
|
+
|
124
|
+
# Speak the translated text
|
125
|
+
MySpeechLibrary.talk(translated)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Use the function
|
129
|
+
translate_and_speak("Hello world", :french)
|
130
|
+
```
|
131
|
+
|
132
|
+
## How It Works
|
133
|
+
|
134
|
+
RubiSpeech uses system commands to provide text-to-speech functionality:
|
135
|
+
|
136
|
+
- On Windows: PowerShell with System.Speech
|
137
|
+
- On macOS: The built-in `say` command
|
138
|
+
- On Linux: The `espeak` command (must be installed)
|
139
|
+
|
140
|
+
## Development
|
141
|
+
|
142
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
143
|
+
|
144
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
145
|
+
|
146
|
+
|
147
|
+
## License
|
148
|
+
|
149
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
150
|
+
|
151
|
+
|
152
|
+
# RubiSpeech
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Example 1: Quick Usage (Direct Method)
|
2
|
+
require 'my_speech_library'
|
3
|
+
|
4
|
+
# Use the helper function for immediate speech
|
5
|
+
MySpeechLibrary.talk("Hello, world!")
|
6
|
+
|
7
|
+
|
8
|
+
# Example 2: Creating and Using an Instance
|
9
|
+
require 'my_speech_library'
|
10
|
+
|
11
|
+
# Create an instance of the main class
|
12
|
+
speech = MySpeechLibrary::Speech.new
|
13
|
+
|
14
|
+
# Use the object to speak text
|
15
|
+
speech.talk("Hello, I'm speaking using RubiSpeech library")
|
16
|
+
|
17
|
+
# Get the current operating system
|
18
|
+
current_os = speech.current_os
|
19
|
+
puts "Current operating system: #{current_os}"
|
20
|
+
|
21
|
+
|
22
|
+
# Example 3: Using the Library in a Script (Multiple Phrases)
|
23
|
+
#!/usr/bin/env ruby
|
24
|
+
require 'my_speech_library'
|
25
|
+
|
26
|
+
# Create a new instance
|
27
|
+
speaker = MySpeechLibrary::Speech.new
|
28
|
+
|
29
|
+
# Phrases to speak
|
30
|
+
phrases = [
|
31
|
+
"Welcome to the Ruby world",
|
32
|
+
"This is a text-to-speech library",
|
33
|
+
"Works on Windows, Mac, and Linux"
|
34
|
+
]
|
35
|
+
|
36
|
+
# Speak each phrase with a time interval
|
37
|
+
phrases.each do |phrase|
|
38
|
+
speaker.talk(phrase)
|
39
|
+
sleep(2) # Wait for 2 seconds between phrases
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Example 4: Direct Use of Different Components
|
44
|
+
require 'my_speech_library'
|
45
|
+
|
46
|
+
# Use the OS detector directly
|
47
|
+
os_detector = MySpeechLibrary::OSDetector.new
|
48
|
+
puts "Is the system Windows? #{os_detector.windows?}"
|
49
|
+
puts "Is the system macOS? #{os_detector.macos?}"
|
50
|
+
puts "Is the system Linux? #{os_detector.linux?}"
|
51
|
+
|
52
|
+
# Use the speaker directly
|
53
|
+
speaker = MySpeechLibrary::Speaker.new(os_detector)
|
54
|
+
speaker.speak("This is a test using the Speaker class directly")
|
55
|
+
|
56
|
+
|
57
|
+
# Example 5: Using the Library in a Simple Translation Application
|
58
|
+
require 'my_speech_library'
|
59
|
+
|
60
|
+
def translate_and_speak(text, language)
|
61
|
+
# This is a hypothetical translation example (in a real app, you'd need a translation service)
|
62
|
+
translated = case language
|
63
|
+
when :english
|
64
|
+
"This is translated to English: " + text
|
65
|
+
when :french
|
66
|
+
"C'est traduit en français: " + text
|
67
|
+
else
|
68
|
+
text
|
69
|
+
end
|
70
|
+
|
71
|
+
# Speak the translated text
|
72
|
+
MySpeechLibrary.talk(translated)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Use the function
|
76
|
+
translate_and_speak("Hello world", :french)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MySpeechLibrary
|
4
|
+
class OSDetector
|
5
|
+
OS_TYPES = {
|
6
|
+
windows: /mswin|mingw|cygwin/,
|
7
|
+
macos: /darwin/,
|
8
|
+
linux: /linux/
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def detect_os
|
12
|
+
@detected_os ||= begin
|
13
|
+
host_os = RbConfig::CONFIG['host_os']
|
14
|
+
|
15
|
+
OS_TYPES.each do |os_type, pattern|
|
16
|
+
return os_type if host_os =~ pattern
|
17
|
+
end
|
18
|
+
|
19
|
+
:unknown
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def windows?
|
24
|
+
detect_os == :windows
|
25
|
+
end
|
26
|
+
|
27
|
+
def macos?
|
28
|
+
detect_os == :macos
|
29
|
+
end
|
30
|
+
|
31
|
+
def linux?
|
32
|
+
detect_os == :linux
|
33
|
+
end
|
34
|
+
|
35
|
+
def unknown?
|
36
|
+
detect_os == :unknown
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MySpeechLibrary
|
4
|
+
class Speaker
|
5
|
+
def initialize(os_detector)
|
6
|
+
@os_detector = os_detector
|
7
|
+
end
|
8
|
+
|
9
|
+
def speak(text)
|
10
|
+
command = speech_command(text)
|
11
|
+
|
12
|
+
if command.nil?
|
13
|
+
error_message = "The operating system #{@os_detector.detect_os} is not supported for voice pronunciation"
|
14
|
+
warn error_message
|
15
|
+
raise UnsupportedOSError, error_message
|
16
|
+
end
|
17
|
+
|
18
|
+
result = system(command)
|
19
|
+
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def speech_command(text)
|
26
|
+
case @os_detector.detect_os
|
27
|
+
when :windows
|
28
|
+
escaped_text = text.gsub("'", "''")
|
29
|
+
%{powershell -Command "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('#{escaped_text}')"}
|
30
|
+
when :macos
|
31
|
+
escaped_text = text.gsub("'", "'\\''")
|
32
|
+
"say '#{escaped_text}'"
|
33
|
+
when :linux
|
34
|
+
escaped_text = text.gsub("'", "'\\''")
|
35
|
+
"espeak '#{escaped_text}'"
|
36
|
+
else
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "my_speech_library/version"
|
4
|
+
require_relative "my_speech_library/os_detector"
|
5
|
+
require_relative "my_speech_library/speaker"
|
6
|
+
|
7
|
+
module MySpeechLibrary
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class Speech
|
11
|
+
def initialize
|
12
|
+
@os_detector = OSDetector.new
|
13
|
+
@speaker = Speaker.new(@os_detector)
|
14
|
+
end
|
15
|
+
|
16
|
+
def talk(text)
|
17
|
+
@speaker.speak(text)
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_os
|
21
|
+
@os_detector.detect_os
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.talk(text)
|
26
|
+
Speech.new.talk(text)
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: RubiSpeech
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maven
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A library for text-to-speech functionality designed for AI applications
|
14
|
+
and natural language processing, with the ability to detect and adapt to the operating
|
15
|
+
system (Windows, macOS, Linux)
|
16
|
+
email:
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- CHANGELOG.md
|
22
|
+
- Gemfile
|
23
|
+
- Rakefile
|
24
|
+
- Readme.md
|
25
|
+
- examples/example-1.rb
|
26
|
+
- lib/my_speech_library.rb
|
27
|
+
- lib/my_speech_library/os_detector.rb
|
28
|
+
- lib/my_speech_library/speaker.rb
|
29
|
+
- lib/my_speech_library/version.rb
|
30
|
+
homepage: https://github.com/Abo5/RubiSpeech
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata:
|
34
|
+
homepage_uri: https://github.com/Abo5/RubiSpeech
|
35
|
+
source_code_uri: https://github.com/Abo5/RubiSpeech
|
36
|
+
changelog_uri: https://github.com/Abo5/RubiSpeech/blob/main/CHANGELOG.md
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.6.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.3.3
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Ruby text-to-speech library for AI applications
|
56
|
+
test_files: []
|