Class: AudioTrack
- Inherits:
-
Object
- Object
- AudioTrack
- Defined in:
- lib/rtrack.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#wavefile ⇒ Object
readonly
Returns the value of attribute wavefile.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #[](slice_range) ⇒ Object
- #export(outpath, format = "mp3", bitrate = "128k") ⇒ Object (also: #save)
-
#initialize(wavefile, duration) ⇒ AudioTrack
constructor
A new instance of AudioTrack.
- #path ⇒ Object
- #seconds ⇒ Object
Constructor Details
#initialize(wavefile, duration) ⇒ AudioTrack
Returns a new instance of AudioTrack.
9 10 11 12 |
# File 'lib/rtrack.rb', line 9 def initialize (wavefile, duration) @wavefile = wavefile @duration = duration end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
7 8 9 |
# File 'lib/rtrack.rb', line 7 def duration @duration end |
#wavefile ⇒ Object (readonly)
Returns the value of attribute wavefile.
7 8 9 |
# File 'lib/rtrack.rb', line 7 def wavefile @wavefile end |
Class Method Details
.from_file(infile) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/rtrack.rb', line 14 def self.from_file(infile) if not (File.exists? infile) fail StandardError, "Couldn't find file from path: #{infile}" end infile = File.open(infile) wavefile = Tempfile.new ['','.wav'] duration = RTrack::Transcoder.to_wave(infile.path, wavefile.path) AudioTrack.new wavefile, duration end |
Instance Method Details
#+(other) ⇒ Object
47 48 49 50 |
# File 'lib/rtrack.rb', line 47 def +(other) info = RTrack::Transcoder.concat @wavefile.path, other.wavefile.path AudioTrack.new info["wavefile"], info["duration"] end |
#[](slice_range) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rtrack.rb', line 32 def [](slice_range) if not slice_range.class == Range fail StandardError, "Invalid slice was given: #{slice_range}" end slice_start, slice_end = slice_range.min, slice_range.max new_wavefile = Tempfile.new ['','.wav'] duration = RTrack::Transcoder.to_slice(@wavefile.path, new_wavefile.path, slice_start, slice_end) AudioTrack.new new_wavefile, duration end |
#export(outpath, format = "mp3", bitrate = "128k") ⇒ Object Also known as: save
52 53 54 55 |
# File 'lib/rtrack.rb', line 52 def export(outpath, format="mp3", bitrate="128k") return_code = RTrack::Transcoder.export(@wavefile.path, outpath, format, bitrate) return_code end |
#path ⇒ Object
28 29 30 |
# File 'lib/rtrack.rb', line 28 def path @wavefile.path end |
#seconds ⇒ Object
24 25 26 |
# File 'lib/rtrack.rb', line 24 def seconds @duration / 1000 end |