voice_chapters 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef4055750ce2b9dd0694488a1169cd0f8f10af4c
4
+ data.tar.gz: 9fbad6245cd2e28f3b707d5fbe1bef16144e0c99
5
+ SHA512:
6
+ metadata.gz: e467aba908c660f9e370d4f63c08d097bd01c4c99db11d89db086ab0b0f4c27ff03779ebb3b24f223841b6864730c6481059bb0fae23b5f065fad14f13b72872
7
+ data.tar.gz: 37205f23fd950eb6a3f094feaeb82bbbd62e5475faa5088885ac34b8d14f5ced125e8be68311f8ad43fe5156b326c5c5b8e2007ed69618dbd92b119d9693e893
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+ audio/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gem "rspec"
3
+ gem 'ruby-debug-ide'
4
+ gem 'chapter'
5
+ # Specify your gem's dependencies in voice_chapters.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dustin Zeisler
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # VoiceChapters
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'voice_chapters'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install voice_chapters
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ class Afinfo
2
+
3
+ def self.file(file_name)
4
+ `afinfo #{file_name}`
5
+ end
6
+
7
+ def self.duration(file_name)
8
+ (self.file(file_name).scan /duration:\s(\d+.\d+)/).flatten.first
9
+ end
10
+
11
+ end
@@ -0,0 +1,27 @@
1
+ class Voice
2
+ def initialize(options = {})
3
+ run_command parse_options options
4
+ end
5
+
6
+ def run_command options
7
+ command = "say #{options} --progress"
8
+ puts command
9
+ system command
10
+ end
11
+
12
+ def parse_options options
13
+ options_string = ""
14
+ options.each do |option, value|
15
+ options_string += "#{create_argument(option, value)} "
16
+ end
17
+ return options_string
18
+ end
19
+
20
+ def create_argument option, value
21
+ if option == :string
22
+ "'#{value}'"
23
+ else
24
+ "--#{option}=#{value}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,74 @@
1
+ #require "voice_chapters/version"
2
+ require_relative "voice"
3
+ require 'digest/sha1'
4
+ require_relative 'afinfo'
5
+ require 'chapter'
6
+
7
+ class Voice_Chapters
8
+ attr_reader :chapters
9
+ def initialize(text:nil, marker:nil, file_name:file_name)
10
+ @text = text
11
+ @file_name = file_name
12
+ chapter_marker(marker)
13
+ create_uuid
14
+ create_audio_for_chapters
15
+ create_audio_for_text
16
+ set_chapter_marker
17
+ clean_chapter_file
18
+ end
19
+
20
+ def chapter_marker(expression)
21
+ @chapters = @text.scan expression
22
+ end
23
+
24
+ def create_uuid
25
+ @uuid = (Digest::SHA1.hexdigest @text)[0...8]
26
+ end
27
+
28
+ def file_name
29
+ @file_names[@uuid] = @chapters
30
+ end
31
+
32
+ def create_audio_for_chapters
33
+ @chapter_files = []
34
+ @chapters.each_with_index do |chapter, index|
35
+ @chapter_files << "#{@uuid}-#{index}.aiff"
36
+ Voice.new({ string: chapter,
37
+ "output-file" => "#{save_dir}/#{@chapter_files.last}" })
38
+ end
39
+ end
40
+
41
+ def chapters_mark_hash
42
+ @chapter_files.each_with_index.map do |file, index|
43
+ {'title' => @chapters[index].first[0..18] + '...', 'duration' => get_file_duration(file)}
44
+ end
45
+ end
46
+
47
+ def get_file_duration(file)
48
+ (Afinfo.duration("#{save_dir}/#{file}").to_f * 1000).ceil
49
+ end
50
+
51
+ def create_audio_for_text
52
+ Voice.new({ string: @text,
53
+ "output-file" => "'#{save_dir}/#{@file_name}.m4a'",
54
+ "file-format" => "m4af" })
55
+ end
56
+
57
+ def set_chapter_marker
58
+ file = "#{save_dir}/#{@file_name}.m4a"
59
+ chapters = chapters_mark_hash
60
+ puts "Chapter.set_chapters('#{file}', #{chapters})"
61
+ Chapter.set_chapters(file, chapters)
62
+ end
63
+
64
+ def save_dir
65
+ File.expand_path('audio',Dir.pwd)
66
+ end
67
+
68
+ def clean_chapter_file
69
+ @chapter_files.each do |file|
70
+ File.delete "#{save_dir}/#{file}"
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,3 @@
1
+ module VoiceChapters
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+ require 'voice_chapters'
3
+
4
+ describe Voice_Chapters do
5
+
6
+ before do
7
+ text = 'In the beginning, God created the heavens and the earth.
8
+ 2 The earth was without form and void, and darkness was over the face
9
+ of the deep. And the Spirit of God was hovering over the face of the waters.
10
+ 3 And God said, “Let there be light,” and there was light.
11
+ 4 And God saw that the light was good. And God separated the
12
+ light from the darkness. 5 God called the light Day, and the
13
+ darkness he called Night. And there was evening and there was morning, the first day.'
14
+ @file_name = 'In_the_Beginning'
15
+ @file_path = ("#{File.expand_path('audio',Dir.pwd)}/#{@file_name}.m4a")
16
+ @voice_chapters = Voice_Chapters.new(text: text,
17
+ file_name: @file_name,
18
+ marker: /(\D+)/) # Mark by verse
19
+ end
20
+
21
+ it "parses text by expression" do
22
+ expect(@voice_chapters.chapters.length).to eq(5)
23
+ end
24
+
25
+ it "makes a file in audio directory named from param" do
26
+ expect(File.exist?(@file_path)).to eq(true)
27
+ end
28
+
29
+ it "has chapters" do
30
+ result = Chapter.chapters @file_path
31
+ expect(result.length).to eq(5)
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ lib = File.expand_path('../lib', __FILE__)
8
+
9
+ require 'rspec'
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'voice_chapters/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "voice_chapters"
8
+ spec.version = '0.0.1'
9
+ spec.authors = ["Dustin Zeisler"]
10
+ spec.email = ["dustin@zive.me"]
11
+ spec.description = %q{Using Mac system text to speech
12
+ read some text and express chapter markers
13
+ and gem will create an m4a file with chapters}
14
+ spec.summary = %q{Using Mac system text to speech
15
+ read some text and express chapter markers
16
+ and gem will create an m4a file with chapters}
17
+ spec.homepage = "https://github.com/zeisler/voice_chapters"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files`.split($/)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(spec|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_runtime_dependency "chapter"
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voice_chapters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dustin Zeisler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chapter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |-
56
+ Using Mac system text to speech
57
+ read some text and express chapter markers
58
+ and gem will create an m4a file with chapters
59
+ email:
60
+ - dustin@zive.me
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rspec
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - lib/afinfo.rb
72
+ - lib/voice.rb
73
+ - lib/voice_chapters.rb
74
+ - lib/voice_chapters/version.rb
75
+ - spec/lib/vocie_chapter_spec.rb
76
+ - spec/spec_helper.rb
77
+ - voice_chapters.gemspec
78
+ homepage: https://github.com/zeisler/voice_chapters
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Using Mac system text to speech read some text and express chapter markers
102
+ and gem will create an m4a file with chapters
103
+ test_files:
104
+ - spec/lib/vocie_chapter_spec.rb
105
+ - spec/spec_helper.rb
106
+ has_rdoc: