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.
Instance Method Summary collapse
-
#each ⇒ Object
return temp file for each chunk.
-
#initialize(original_file, chunk_duration = 8, overlap = 1) ⇒ ChunkFactory
constructor
A new instance of ChunkFactory.
- #logger ⇒ Object
Constructor Details
#initialize(original_file, chunk_duration = 8, overlap = 1) ⇒ ChunkFactory
Returns a new instance of ChunkFactory.
9 10 11 12 13 14 |
# File 'lib/google_speech/chunk_factory.rb', line 9 def initialize(original_file, chunk_duration=8, overlap=1) @chunk_duration = chunk_duration @original_file = original_file @overlap = overlap @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 |
Instance Method Details
#each ⇒ Object
return temp file for each chunk
17 18 19 20 21 22 23 24 |
# File 'lib/google_speech/chunk_factory.rb', line 17 def each pos = 0 while(pos < @original_duration) do chunk = Chunk.new(@original_file, @original_duration, pos, (@chunk_duration + @overlap)) yield chunk pos = pos + [chunk.duration, @chunk_duration].min end end |
#logger ⇒ Object
26 27 28 |
# File 'lib/google_speech/chunk_factory.rb', line 26 def logger GoogleSpeech.logger end |