alba_habla 0.0.1
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/README.md +19 -0
- data/bin/alba_habla +19 -0
- data/lib/alba_habla.rb +89 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 347e188fb36dc48d56e0fb6722c448f7c505bf8a
|
4
|
+
data.tar.gz: df82debec97f3e2cf4ea431c2b419f658af5d124
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12dcdcde86afef2a4bba5abcbf3f9eb8502a3a6ec3f8bb584b544e7e8dc4a8ee7970136e3eb3f798e3488a20a025105e8d7c4a9dd1f7c307a99f9663e0eeae42
|
7
|
+
data.tar.gz: 525b8029f3d8c88f47b83476a310f189209241ade9d750fee52165192c26fd5829c0aeee3c35adb053c72e9fb74a0989c2f3bee2369cac3a7633a1dc12e81fb0
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Alba Habla
|
2
|
+
|
3
|
+
_A fun little wrapper around you OS's speech synthesizer_
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
$ git clone git@github.com:mertonium/alba_habla.git
|
9
|
+
$ cd alba_habla
|
10
|
+
$ gem build alba_habla.gemspec
|
11
|
+
$ gem install ./alba_habla-0.0.1.gem
|
12
|
+
```
|
13
|
+
|
14
|
+
## Execution
|
15
|
+
|
16
|
+
```bash
|
17
|
+
$ alba_habla
|
18
|
+
```
|
19
|
+
|
data/bin/alba_habla
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'io/console'
|
3
|
+
require 'alba_habla'
|
4
|
+
|
5
|
+
ah = AlbaHabla.new(File.expand_path(File.dirname(__FILE__)) + '/books/')
|
6
|
+
|
7
|
+
command = nil
|
8
|
+
command_history = []
|
9
|
+
|
10
|
+
# Main program loop
|
11
|
+
while command != 'bye'
|
12
|
+
print 'What shall I say? '
|
13
|
+
command = gets.chomp
|
14
|
+
command_history.push command
|
15
|
+
ah.process_command(command)
|
16
|
+
end
|
17
|
+
|
18
|
+
puts 'COMMAND HISTORY'
|
19
|
+
command_history.each { |h| puts h }
|
data/lib/alba_habla.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Main class used to process commands
|
2
|
+
class AlbaHabla
|
3
|
+
attr_reader :voice
|
4
|
+
|
5
|
+
VERSION = '0.0.1'.freeze
|
6
|
+
|
7
|
+
DEFAULT_VOICES = {
|
8
|
+
'say' => 'Fiona',
|
9
|
+
'espeak' => 'en-westindies'
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
def initialize(book_path)
|
13
|
+
@voice = DEFAULT_VOICES[executable]
|
14
|
+
@book_path = book_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def process_command(command)
|
18
|
+
subcommand = command.split(' ').first
|
19
|
+
if available_subcommands.include? subcommand
|
20
|
+
send(subcommand, command.split(' ')[1..-1].join(' '))
|
21
|
+
else
|
22
|
+
talk(command)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def executable
|
29
|
+
@executable ||= %w[espeak say].reject do |ex|
|
30
|
+
`which #{ex}` == ''
|
31
|
+
end.first
|
32
|
+
end
|
33
|
+
|
34
|
+
def cli_options
|
35
|
+
"-v #{voice}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def talk_command
|
39
|
+
"#{executable} #{cli_options}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def talk(string)
|
43
|
+
`#{talk_command} "#{string}"`
|
44
|
+
end
|
45
|
+
|
46
|
+
def books
|
47
|
+
{
|
48
|
+
'sam' => 'green_eggs_and_ham.txt',
|
49
|
+
'cat' => 'the_cat_in_the_hat.txt',
|
50
|
+
'ladybird' => 'what_the_ladybird_heard.txt',
|
51
|
+
'ladybird2' => 'what_the_lady_bird_heard_next.txt',
|
52
|
+
'fox' => 'fox_in_socks.txt'
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def word_bag
|
57
|
+
@word_bag || begin
|
58
|
+
bag = []
|
59
|
+
books.values.each do |book_file|
|
60
|
+
IO.foreach(@book_path + book_file) do |line|
|
61
|
+
bag << line.gsub(/[,'\.!\?]/, '').split(' ')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
bag.flatten.compact.uniq
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def read(book_name)
|
69
|
+
if books.key? book_name
|
70
|
+
IO.foreach(@book_path + books[book_name]) do |line|
|
71
|
+
puts line
|
72
|
+
talk line.delete('"')
|
73
|
+
end
|
74
|
+
else
|
75
|
+
talk "Sorry, I don't know that book. Ask Daddy to add it."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def spell(_)
|
80
|
+
word = word_bag.sample
|
81
|
+
puts word.downcase
|
82
|
+
talk "Let's spell #{word}."
|
83
|
+
talk word.split('').join(' ').to_s
|
84
|
+
end
|
85
|
+
|
86
|
+
def available_subcommands
|
87
|
+
%w[read spell]
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alba_habla
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mertonium
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.49'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.49'
|
41
|
+
description: A simple little program that reads back what you type.
|
42
|
+
email: j@j10z.xyz
|
43
|
+
executables:
|
44
|
+
- alba_habla
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- bin/alba_habla
|
50
|
+
- lib/alba_habla.rb
|
51
|
+
homepage: https://github.com/mertonium/alba_habla
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.6.11
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Type something, read it back.
|
75
|
+
test_files: []
|