Class: GoogleSpeech::ChunkFactory
- Inherits:
-
Object
- Object
- GoogleSpeech::ChunkFactory
- Defined in:
- lib/google_speech/chunk_factory.rb
Overview
break wav audio into short files
Instance Attribute Summary collapse
-
#chunk_duration ⇒ Object
Returns the value of attribute chunk_duration.
-
#original_file ⇒ Object
Returns the value of attribute original_file.
-
#overlap ⇒ Object
Returns the value of attribute overlap.
-
#rate ⇒ Object
Returns the value of attribute rate.
Instance Method Summary collapse
-
#each ⇒ Object
return temp file for each chunk.
-
#initialize(original_file, chunk_duration, overlap, rate) ⇒ ChunkFactory
constructor
A new instance of ChunkFactory.
- #logger ⇒ Object
Constructor Details
#initialize(original_file, chunk_duration, overlap, rate) ⇒ ChunkFactory
Returns a new instance of ChunkFactory.
9 10 11 12 13 14 15 |
# File 'lib/google_speech/chunk_factory.rb', line 9 def initialize(original_file, chunk_duration, overlap, rate) @chunk_duration = chunk_duration @original_file = original_file @overlap = overlap @rate = rate @original_duration = GoogleSpeech::Utility.audio_file_duration(@original_file.path) end |
Instance Attribute Details
#chunk_duration ⇒ Object
Returns the value of attribute chunk_duration.
7 8 9 |
# File 'lib/google_speech/chunk_factory.rb', line 7 def chunk_duration @chunk_duration end |
#original_file ⇒ Object
Returns the value of attribute original_file.
7 8 9 |
# File 'lib/google_speech/chunk_factory.rb', line 7 def original_file @original_file end |
#overlap ⇒ Object
Returns the value of attribute overlap.
7 8 9 |
# File 'lib/google_speech/chunk_factory.rb', line 7 def overlap @overlap end |
#rate ⇒ Object
Returns the value of attribute rate.
7 8 9 |
# File 'lib/google_speech/chunk_factory.rb', line 7 def rate @rate end |
Instance Method Details
#each ⇒ Object
return temp file for each chunk
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/google_speech/chunk_factory.rb', line 18 def each pos = 0 while(pos < @original_duration) do chunk = nil begin chunk = Chunk.new(@original_file, @original_duration, pos, (@chunk_duration + @overlap), @rate) yield chunk pos = pos + [chunk.duration, @chunk_duration].min ensure chunk.close_file if chunk end end end |
#logger ⇒ Object
32 33 34 |
# File 'lib/google_speech/chunk_factory.rb', line 32 def logger GoogleSpeech.logger end |