Class: Praat::Intervals

Inherits:
MetaObject show all
Defined in:
lib/praat_textgrid.rb

Overview

Currently, we can only extract one IntervalTier at a time Intervals is actually a single interval (thx, Praat)

Instance Attribute Summary

Attributes inherited from MetaObject

#parent

Instance Method Summary collapse

Methods inherited from MetaObject

#add_property, #add_to_collection, #to_json, #to_s

Instance Method Details

#extract_formant(formant) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/praat_textgrid.rb', line 34

def extract_formant formant
  out = Marshal.load(Marshal.dump(formant))
  out.frames.clear
  x1 = formant.x1
  dx = formant.dx
  # Select the frames which fall within the range of the textgrid
  formant.frames.each_with_index do |f, i|
    time = i * dx + x1
    if range.include? time
      out.frames << f
    end
  end
  out
end

#extract_pitch(pitch) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/praat_textgrid.rb', line 19

def extract_pitch pitch
  out = Marshal.load(Marshal.dump(pitch))
  out.frames.clear
  x1 = pitch.x1
  dx = pitch.dx
  # Select the frames which fall within the pitch range
  pitch.frames.each_with_index do |f, i|
    time = i * dx + x1
    if range.include? time
      out.frames << f
    end
  end
  out
end

#has_text?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/praat_textgrid.rb', line 7

def has_text?
  self.text != ""
end

#minmaxObject



11
12
13
# File 'lib/praat_textgrid.rb', line 11

def minmax
  [self.xmin, self.xmax]
end

#rangeObject



15
16
17
# File 'lib/praat_textgrid.rb', line 15

def range
  Range.new(self.xmin, self.xmax)
end