kja 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/kja.rb +93 -25
  4. data.tar.gz.sig +0 -0
  5. metadata +52 -28
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a494c0ef1730b6813f9f86b400f24cd93882a2dc
4
- data.tar.gz: 58270c1e3e31f06251481c8fccc74e192af24cfe
2
+ SHA256:
3
+ metadata.gz: 1228c3a17d36ddc53f837e4e8d5b4000dd9554d38f621dc2495e3b03f6da64ac
4
+ data.tar.gz: da86bc75e88decc6d04a799dfc25dc645a7c515b0a2bbbf9fcf0cae1a68e7c8c
5
5
  SHA512:
6
- metadata.gz: daf2bd34d8f5e627b55b69d033949f1f549f7c1aae99c3a5579df21d87c27e43abe0d72c274b039dfbd162e5e43b34759b3bfd210ca2d86e8fb2e0832ffbfe8f
7
- data.tar.gz: 9dd62dd936930c8dde16ea6a80dbb988b406e2c6d09f2c5a4f3a3c8c31e06a531907e0bc09ccb4c8b47b9f05b0c49f16b03c409313cb3208865d14c23ae6b9a1
6
+ metadata.gz: f252c1900dc380411faed4fe482d1279c1599279e7d01133abd07be300b33cfc6e0036b403db8707431b4dbeef5e2b324fd82f5cfc0dbcda175a8bae92f83f85
7
+ data.tar.gz: 8f9395c86fc703766d69df3c1c1d378c925d59344885f07d4d1a46380ce0264f03859b7618dc3ccdb160899c0ed4d24f2cb5606eb9ed531e68b074bcabc734b7
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/kja.rb CHANGED
@@ -4,6 +4,9 @@
4
4
 
5
5
  require 'dynarex'
6
6
  require 'tempfile'
7
+ require 'rxfreader'
8
+ require 'kj_reading'
9
+ require 'easyaudio_utils'
7
10
 
8
11
 
9
12
  # description: Intended for use with the kj gem
@@ -25,57 +28,122 @@ require 'tempfile'
25
28
 
26
29
  class Kja
27
30
 
28
- def initialize(audio_player: '/usr/bin/ogg123 -q',
29
- ogg_baseurl: 'http://rorbuilder.info/r/ruby/kja/ogg')
31
+ def initialize(audio_player: '/usr/bin/ogg123 -q',
32
+ ogg_baseurl: 'http://a0.jamesrobertson.me.uk/' \
33
+ + 'rorb/r/ruby/kja/ogg', debug: false)
30
34
 
31
35
  @ogg_baseurl, @audio_player = ogg_baseurl, audio_player
36
+ @debug = debug
32
37
 
33
38
  end
34
-
39
+
35
40
  def duration(s)
36
41
 
37
- book_no, book_title, chapter_no, verse_no = \
38
- s.downcase.match(/^(?:(\d) )?([\w ]+) (\d+):(\d+)/).captures
42
+ book_title, chapter_title, verse_no = fracture(s)
39
43
 
40
- book_title = book_no + '_' + book_title if book_no
41
- chapter_title = book_title + '_' + chapter_no
42
44
  url = @ogg_baseurl + '/' + File.join(book_title, chapter_title, 'dir.xml')
43
45
 
44
46
  dx = Dynarex.new url
45
- ogg = dx.find_by_name chapter_title + '_' + verse_no + '.ogg'
47
+ ogg = dx.find_by_name chapter_title + '_' + verse_no + '.ogg'
46
48
  ogg.description[/\d+\.\d+$/].to_f
47
49
 
48
- end
50
+ end
51
+
52
+ # e.g. speak 'Eze 18, 30..32'
53
+ # plays the audio of the title requested
54
+ #
55
+ def speak(title)
56
+
57
+ a = KjReading.verses title
58
+
59
+ a.each do |x|
60
+
61
+ filename = download_ogg(x.title)
62
+ command = @audio_player + ' ' + filename
63
+ system command
64
+
65
+ end
66
+
67
+ end
68
+
69
+ # e.g. download 'Eze 18, 30..32'
70
+ # downloads the audio as an ogg file
71
+ #
72
+ def download(s, outfile=nil)
73
+
74
+ puts 'downloading ...' if @debug
75
+
76
+ a = KjReading.verses s
77
+
78
+ downloads = a.map do |x|
79
+ download_ogg(x.title)
80
+ end
81
+
82
+ puts 'converting to wav: ' + downloads.inspect if @debug
83
+
84
+ dir = File.dirname(Tempfile.new.path)
85
+
86
+ wavfiles = downloads.map do |oggfile|
87
+
88
+ wavfile = oggfile.sub(/\.ogg$/,'.wav')
89
+ EasyAudioUtils.new(oggfile, wavfile, working_dir: dir).convert
90
+ sleep 1.4
91
+ File.basename(wavfile)
49
92
 
50
- def speak(s)
93
+ end
94
+
95
+ puts 'concatenating wav files ...' if @debug
96
+
97
+ # concat wav files
98
+ #
99
+ fullwavfile = Tempfile.new('kva').path + '.wav'
100
+ puts 'creating fullwavfile:' + fullwavfile.inspect if @debug
101
+ EasyAudioUtils.new(out: fullwavfile, working_dir: dir).concat(wavfiles,
102
+ sample_rate: 22050)
103
+
104
+ # convert wav to ogg
105
+ #
106
+ fulloggfile = outfile || fullwavfile.sub(/\.wav$/, '.ogg')
107
+ puts 'creating fulloggfile: ' + fulloggfile.inspect if @debug
108
+ EasyAudioUtils.new(fullwavfile, fulloggfile).convert
109
+
110
+ 'downloaded ' + fulloggfile
111
+
112
+ end
113
+
114
+ private
115
+
116
+ def download_ogg(s)
51
117
 
52
118
  ogg_filepath = fetch_ogg_filepath(s)
53
119
  url = @ogg_baseurl + '/' + ogg_filepath
54
- audio, _ = RXFHelper.read(url)
55
-
120
+ audio, _ = RXFReader.read(url)
121
+
56
122
  tmpfile = Tempfile.new('kva')
57
- file = File.new(tmpfile.path,'w')
58
- file.puts audio
59
- file.close
123
+ File.write tmpfile.path + '.ogg', audio
60
124
 
61
- command = @audio_player + ' ' + tmpfile.path
62
- system command
125
+ return tmpfile.path + '.ogg'
63
126
 
64
127
  end
65
-
66
- private
67
-
68
-
69
- def fetch_ogg_filepath(s)
70
-
128
+
129
+ def fracture(s)
130
+
71
131
  book_no, book_title, chapter_no, verse_no = \
72
- s.downcase.match(/^(?:(\d) )?([\w ]+) (\d+):(\d+)/).captures
132
+ s.downcase.match(/(?:(\d) )?([\w ]+) (\d+):(\d+)$/).captures
73
133
 
134
+ book_title.gsub!(/\s/,'_')
74
135
  book_title = book_no + '_' + book_title if book_no
75
136
  chapter_title = book_title + '_' + chapter_no
137
+
138
+ return [book_title, chapter_title, verse_no]
139
+ end
140
+
141
+ def fetch_ogg_filepath(s)
142
+
143
+ book_title, chapter_title, verse_no = fracture(s)
76
144
  verse_title = chapter_title + '_' + verse_no
77
145
 
78
- File.join(book_title, chapter_title, verse_title + '.ogg')
146
+ File.join(book_title, chapter_title, verse_title + '.ogg')
79
147
  end
80
148
 
81
149
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kja
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,28 +10,33 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
13
+ MIIEljCCAv6gAwIBAgIBATANBgkqhkiG9w0BAQsFADBIMRIwEAYDVQQDDAlnZW1t
14
14
  YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE3MDYxMTEzMTUzMVoXDTE4MDYxMTEzMTUzMVowSDESMBAG
15
+ 8ixkARkWAmV1MB4XDTIyMDcxNTA3NTY0OVoXDTIzMDcxNTA3NTY0OVowSDESMBAG
16
16
  A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAK7GZ3j4h3A8ZZRfP2QrDoCpKcSrlz8TP6/swOSGfdRlEvgKSJW7bh0ux8U3
19
- /pGQiqPNPGoXSZ1cOCzTDhxOxH4X7EFCWhcJmPoi8v7ikbjKajsIMId/X8QT+/dU
20
- GG1pI8luFMk60aQTccEIFJhnZeFEPL7RC21svJSTkIb6/7ZbA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tHatBTStNKF7ng7zTIPYHWc7YUDamV
37
+ c/p/VO0efUKyKAHzOQQe8VZzcgh6e7jVIws=
33
38
  -----END CERTIFICATE-----
34
- date: 2017-06-14 00:00:00.000000000 Z
39
+ date: 2022-07-15 00:00:00.000000000 Z
35
40
  dependencies:
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: dynarex
@@ -39,22 +44,42 @@ dependencies:
39
44
  requirements:
40
45
  - - "~>"
41
46
  - !ruby/object:Gem::Version
42
- version: '1.7'
47
+ version: '1.9'
43
48
  - - ">="
44
49
  - !ruby/object:Gem::Version
45
- version: 1.7.22
50
+ version: 1.9.11
46
51
  type: :runtime
47
52
  prerelease: false
48
53
  version_requirements: !ruby/object:Gem::Requirement
49
54
  requirements:
50
55
  - - "~>"
51
56
  - !ruby/object:Gem::Version
52
- version: '1.7'
57
+ version: '1.9'
53
58
  - - ">="
54
59
  - !ruby/object:Gem::Version
55
- version: 1.7.22
60
+ version: 1.9.11
61
+ - !ruby/object:Gem::Dependency
62
+ name: kj_reading
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.3'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 0.3.0
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '0.3'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 0.3.0
56
81
  description:
57
- email: james@jamesrobertson.eu
82
+ email: digital.robertson@gmail.com
58
83
  executables: []
59
84
  extensions: []
60
85
  extra_rdoc_files: []
@@ -79,9 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
104
  - !ruby/object:Gem::Version
80
105
  version: '0'
81
106
  requirements: []
82
- rubyforge_project:
83
- rubygems_version: 2.6.8
107
+ rubygems_version: 3.3.7
84
108
  signing_key:
85
109
  specification_version: 4
86
- summary: Downloads and plays King James Bible OGG files from rorbuilder.info
110
+ summary: Downloads and plays King James Bible OGG files from jamesrobertson.me.uk
87
111
  test_files: []
metadata.gz.sig CHANGED
Binary file