Class: Diarize::Segment

Inherits:
Object
  • Object
show all
Includes:
ToRdf
Defined in:
lib/diarize/segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audio, start, duration, gender, bandwidth, speaker_id) ⇒ Segment

Returns a new instance of Segment.



29
30
31
32
33
34
35
36
# File 'lib/diarize/segment.rb', line 29

def initialize(audio, start, duration, gender, bandwidth, speaker_id)
  @audio = audio
  @start = start
  @duration = duration
  @bandwidth = bandwidth
  @speaker_id = speaker_id
  @speaker_gender = gender
end

Instance Attribute Details

#bandwidthObject (readonly)

Returns the value of attribute bandwidth.



27
28
29
# File 'lib/diarize/segment.rb', line 27

def bandwidth
  @bandwidth
end

#durationObject (readonly)

Returns the value of attribute duration.



27
28
29
# File 'lib/diarize/segment.rb', line 27

def duration
  @duration
end

#genderObject (readonly)

Returns the value of attribute gender.



27
28
29
# File 'lib/diarize/segment.rb', line 27

def gender
  @gender
end

#startObject (readonly)

Returns the value of attribute start.



27
28
29
# File 'lib/diarize/segment.rb', line 27

def start
  @start
end

Instance Method Details

#namespacesObject



49
50
51
# File 'lib/diarize/segment.rb', line 49

def namespaces
  super.merge 'ws' => 'http://wsarchive.prototype0.net/ontology/'
end

#playObject



42
43
44
45
# File 'lib/diarize/segment.rb', line 42

def play
  player = AudioPlayer.new
  player.play(@audio.file, start, duration)
end

#rdf_mappingObject



62
63
64
65
66
67
68
69
70
# File 'lib/diarize/segment.rb', line 62

def rdf_mapping
  {
    'ws:start' => start,
    'ws:duration' => duration,
    'ws:gender' => gender,
    'ws:bandwidth' => bandwidth,
    'ws:speaker' => speaker,
  }
end

#speakerObject



38
39
40
# File 'lib/diarize/segment.rb', line 38

def speaker
  Speaker.find_or_create(URI("#{@audio.base_uri}##{@speaker_id}"), @speaker_gender)
end

#type_uriObject



58
59
60
# File 'lib/diarize/segment.rb', line 58

def type_uri
  'ws:Segment'
end

#uriObject



53
54
55
56
# File 'lib/diarize/segment.rb', line 53

def uri
  # http://www.w3.org/TR/media-frags/
  URI("#{@audio.base_uri}#t=#{start},#{start+duration}")
end