voxbi 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d1e9129064fe112b7ed8c8f3dc8c77c614a64fa
4
- data.tar.gz: 81db7b7d05fedf7cb5b36cf055874aab4be19af7
3
+ metadata.gz: 41108b63c80b692d9f0c3eba09782a7565c6bd68
4
+ data.tar.gz: 465f1b68e7ee7e455bfe3bffc074322f8478f257
5
5
  SHA512:
6
- metadata.gz: 1448af100511cc73c6eea9f4b8cfc84f3a4066cc2dc2992ed4b190ff8b0b56c5002b4dd7160e29cb81df3fd976fe650b9c76f8dd570ce1827e8042a30c3c51a9
7
- data.tar.gz: 49a858265edda4769b8734d451d359879afb64c396d8bf29f36bb3da1baf0b2b37c4e200f9a1c192dbd25b7281b707459fe8ec085c45d58253af3a1bba243a14
6
+ metadata.gz: 65a76f3ed1361264dad019b6926c0ca03f4b5529cb0a1849691dbf62eda709f0c3ef87235f54356c4b525507e72bf1b8d0605e63b6b856fc63e92054b659fd52
7
+ data.tar.gz: 2f6b3087dbee91a0fc32397bda8c94de254f9b5fa1e860356824f9450328ae399917549322568fa6573c22fdaada08f524c7394a5889437a358928a510847b60
data/data/pairs.wav CHANGED
Binary file
@@ -0,0 +1,30 @@
1
+ require "json"
2
+ require "csv"
3
+
4
+ module RuleParsable
5
+ DATA_PATH = File.expand_path('../../data', __dir__)
6
+
7
+ def self.included(klass)
8
+ klass.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ def parse_rule_file(filename, file_format)
13
+ absolute_file_path = absolute_path_for(filename, file_format)
14
+
15
+ case file_format
16
+ when :csv then parse_csv(absolute_file_path)
17
+ when :json then JSON.parse(File.read(absolute_file_path))
18
+ end
19
+ end
20
+
21
+ def parse_csv(file_path)
22
+ parsed_csv = CSV.read(file_path, col_sep: '#')
23
+ parsed_csv.first.length > 1 ? Hash[parsed_csv] : parsed_csv.flatten
24
+ end
25
+
26
+ def absolute_path_for(filename, file_format)
27
+ "#{DATA_PATH}/#{filename}" + ".#{file_format}"
28
+ end
29
+ end
30
+ end
data/lib/rule_store.rb ADDED
@@ -0,0 +1,22 @@
1
+ class RuleStore
2
+ include RuleParsable
3
+
4
+ CSV_FILENAMES = %i(conversion linkage exceptions available_pairs).freeze
5
+ JSON_FILENAMES = %i(dictionary).freeze
6
+
7
+ def self.class_memoize(filename, file_format)
8
+ class_variable_set(:"@@#{filename}", parse_rule_file(filename, file_format))
9
+
10
+ self.define_singleton_method(filename) do
11
+ class_variable_get(:"@@#{filename}")
12
+ end
13
+ end
14
+
15
+ CSV_FILENAMES.each do |filename|
16
+ class_memoize filename, :csv
17
+ end
18
+
19
+ JSON_FILENAMES.each do |filename|
20
+ class_memoize filename, :json
21
+ end
22
+ end
@@ -1,8 +1,4 @@
1
1
  class GetPairsService
2
- include Rulable
3
-
4
- memoize_csv :available_pairs
5
-
6
2
  attr_reader :phonetic_text
7
3
 
8
4
  def initialize(phonetic_text)
@@ -22,7 +18,7 @@ class GetPairsService
22
18
 
23
19
  [].tap do |pairs|
24
20
  while word.length != 0
25
- matching_pair = available_pairs.detect{ |pair| word.match(/^#{pair}/) }
21
+ matching_pair = RuleStore.available_pairs.detect{ |pair| word.match(/^#{pair}/) }
26
22
  word.sub!(/^#{matching_pair}/,"")
27
23
  pairs << matching_pair
28
24
  end
@@ -1,8 +1,4 @@
1
1
  class LinkageService
2
- include Rulable
3
-
4
- memoize_csv :linkage
5
-
6
2
  attr_accessor :prepared_text, :phonetic_text
7
3
 
8
4
  def initialize(prepared_text, phonetic_text)
@@ -36,6 +32,6 @@ class LinkageService
36
32
  end
37
33
 
38
34
  def linkage_rule_for(link_string)
39
- linkage.select {|k,v| link_string =~ /#{k}/ }.first
35
+ RuleStore.linkage.select {|k,v| link_string =~ /#{k}/ }.first
40
36
  end
41
37
  end
@@ -1,10 +1,6 @@
1
1
  require "timeout"
2
2
 
3
3
  class PhoneticsConverterService
4
- include Rulable
5
-
6
- memoize_csv :conversion
7
-
8
4
  DEFAULT_TIMEOUT = 5.freeze
9
5
 
10
6
  attr_accessor :word, :phonetized_word
@@ -39,6 +35,6 @@ class PhoneticsConverterService
39
35
  end
40
36
 
41
37
  def conversion_rule_for(word)
42
- conversion.detect{ |rule, phonetic| word =~ /#{rule}/ }
38
+ RuleStore.conversion.detect{ |rule, phonetic| word =~ /#{rule}/ }
43
39
  end
44
40
  end
data/lib/voxbi.rb CHANGED
@@ -5,10 +5,6 @@ File.expand_path('..', __dir__).tap do |root_path|
5
5
  end
6
6
 
7
7
  class Voxbi
8
- include Rulable
9
-
10
- memoize_json :dictionary
11
-
12
8
  attr_accessor :text
13
9
 
14
10
  ROOT_PATH = File.expand_path('..', __dir__).freeze
@@ -46,7 +42,7 @@ class Voxbi
46
42
 
47
43
  def phonetic_text
48
44
  @phonetic_text ||= prepared_text.map do |word|
49
- dictionary[word] ||
45
+ RuleStore.dictionary[word] ||
50
46
  PhoneticsConverterService.new(word).call
51
47
  end
52
48
  end
data/voxbi-1.0.4.gem ADDED
Binary file
data/voxbi.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'voxbi'
3
- s.version = '1.0.4'
3
+ s.version = '1.0.5'
4
4
  s.date = '2018-04-03'
5
5
  s.summary = "VoxBi"
6
6
  s.description = "Easy-to-use french voice synthesizer"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voxbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Galaad Gauthier
@@ -318,7 +318,8 @@ files:
318
318
  - data/pairs/σ.ogg
319
319
  - data/pairs/ϵ.ogg
320
320
  - lib/extensions/string.rb
321
- - lib/modules/rulable.rb
321
+ - lib/modules/rule_parsable.rb
322
+ - lib/rule_store.rb
322
323
  - lib/services/get_pairs_service.rb
323
324
  - lib/services/get_syllables_service.rb
324
325
  - lib/services/linkage_service.rb
@@ -326,6 +327,7 @@ files:
326
327
  - lib/services/prepare_text_service.rb
327
328
  - lib/voxbi.rb
328
329
  - voxbi-1.0.1.gem
330
+ - voxbi-1.0.4.gem
329
331
  - voxbi-1.0.gem
330
332
  - voxbi.gemspec
331
333
  homepage: https://github.com/Galaad-Gauthier/VoxBi
@@ -1,56 +0,0 @@
1
- require "json"
2
- require "csv"
3
-
4
- module Rulable
5
- DATA_PATH = File.expand_path('../../data', __dir__)
6
- CSV_FILENAMES = %i(conversion linkage exceptions available_pairs).freeze
7
- JSON_FILENAMES = %i(dictionary).freeze
8
-
9
- def self.included(klass)
10
- klass.extend(Macros)
11
- end
12
-
13
- def memoize_file_content(filename, file_format)
14
- instance_variable_get("@#{filename}") ||
15
- instance_variable_set("@#{filename}", parse_rule_file(filename, file_format))
16
- end
17
-
18
- def parse_rule_file(filename, file_format)
19
- absolute_file_path = absolute_path_for(filename, file_format)
20
-
21
- case file_format
22
- when :csv then parse_csv(absolute_file_path)
23
- when :json then JSON.parse(File.read(absolute_file_path))
24
- end
25
- end
26
-
27
- def parse_csv(file_path)
28
- parsed_csv = CSV.read(file_path, col_sep: '#')
29
-
30
- parsed_csv.first.length > 1 ? Hash[parsed_csv] : parsed_csv.flatten
31
- end
32
-
33
- def absolute_path_for(filename, file_format)
34
- "#{DATA_PATH}/#{filename}" + ".#{file_format}"
35
- end
36
-
37
- module Macros
38
- def memoize_csv(*filenames)
39
- permitted_filenames = filenames.select{ |filename| CSV_FILENAMES.include?(filename) }
40
- memoize_file(permitted_filenames, file_format: :csv)
41
- end
42
-
43
- def memoize_json(*filenames)
44
- permitted_filenames = filenames.select{ |filename| JSON_FILENAMES.include?(filename) }
45
- memoize_file(permitted_filenames, file_format: :json)
46
- end
47
-
48
- def memoize_file(filenames, file_format:)
49
- filenames.each do |filename|
50
- define_method(filename) do
51
- memoize_file_content(filename, file_format)
52
- end
53
- end
54
- end
55
- end
56
- end