Class: Diarize::Audio
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #analyze!(train_speaker_models = true) ⇒ Object
- #base_uri ⇒ Object
- #clean! ⇒ Object
- #duration_by_speaker(speaker) ⇒ Object
-
#initialize(uri) ⇒ Audio
constructor
A new instance of Audio.
- #namespaces ⇒ Object
- #rdf_mapping ⇒ Object
- #segments ⇒ Object
- #segments_by_speaker(speaker) ⇒ Object
- #show ⇒ Object
- #speakers ⇒ Object
- #top_speakers ⇒ Object
- #type_uri ⇒ Object
- #type_uri=(type_uri) ⇒ Object
- #uri ⇒ Object
- #uri=(uri) ⇒ Object
Constructor Details
#initialize(uri) ⇒ Audio
Returns a new instance of Audio.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/diarize/audio.rb', line 31 def initialize(uri) @uri = uri if uri.scheme == 'file' # Local file @path = uri.path else # Remote file, we get it locally @path = '/tmp/' + URI.escape(uri.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) Kernel.system("wget #{uri} -O #{@path}") end @file = File.new @path end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
29 30 31 |
# File 'lib/diarize/audio.rb', line 29 def file @file end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
29 30 31 |
# File 'lib/diarize/audio.rb', line 29 def path @path end |
Instance Method Details
#analyze!(train_speaker_models = true) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/diarize/audio.rb', line 44 def analyze!(train_speaker_models = true) parameter = fr.lium.spkDiarization.parameter.Parameter.new parameter.show = show # 12 MFCC + Energy # 1: static coefficients are present in the file # 1: energy coefficient is present in the file # 0: delta coefficients are not present in the file # 0: delta energy coefficient is not present in the file # 0: delta delta coefficients are not present in the file # 0: delta delta energy coefficient is not present in the file # 13: total size of a feature vector in the mfcc file # 0:0:0: no feature normalization parameter.parameterInputFeature.setFeaturesDescription('audio2sphinx,1:1:0:0:0:0,13,0:0:0:0') parameter.parameterDiarization.cEClustering = true # We use CE clustering by default parameter.parameterInputFeature.setFeatureMask(@path) @clusters = ester2(parameter) @segments = Segmentation.from_clusters(self, @clusters) train_speaker_gmms if train_speaker_models end |
#base_uri ⇒ Object
109 110 111 112 113 114 |
# File 'lib/diarize/audio.rb', line 109 def base_uri # Remove the fragment if there is one base = uri.clone base.fragment = nil base end |
#clean! ⇒ Object
64 65 66 67 |
# File 'lib/diarize/audio.rb', line 64 def clean! return if @uri.scheme == 'file' # Don't delete local file if initialised from local URI File.delete(@path) end |
#duration_by_speaker(speaker) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/diarize/audio.rb', line 83 def duration_by_speaker(speaker) return unless speaker segments = segments_by_speaker(speaker) duration = 0.0 segments.each { |segment| duration += segment.duration } duration end |
#namespaces ⇒ Object
97 98 99 |
# File 'lib/diarize/audio.rb', line 97 def namespaces super.merge 'ws' => 'http://wsarchive.prototype0.net/ontology/', 'mo' => 'http://purl.org/ontology/mo/' end |
#rdf_mapping ⇒ Object
124 125 126 |
# File 'lib/diarize/audio.rb', line 124 def rdf_mapping { 'ws:segment' => segments } end |
#segments ⇒ Object
69 70 71 72 |
# File 'lib/diarize/audio.rb', line 69 def segments raise Exception.new('You need to run analyze! before being able to access the analysis results') unless @segments @segments end |
#segments_by_speaker(speaker) ⇒ Object
79 80 81 |
# File 'lib/diarize/audio.rb', line 79 def segments_by_speaker(speaker) segments.select { |segment| segment.speaker == speaker } end |
#show ⇒ Object
128 129 130 131 |
# File 'lib/diarize/audio.rb', line 128 def show # The LIUM show name will be the file name, without extension or directory File.(@path).split('/')[-1].split('.')[0] end |
#speakers ⇒ Object
74 75 76 77 |
# File 'lib/diarize/audio.rb', line 74 def speakers return @speakers if @speakers @speakers = segments.map { |segment| segment.speaker }.uniq end |
#top_speakers ⇒ Object
91 92 93 |
# File 'lib/diarize/audio.rb', line 91 def top_speakers speakers.sort {|s1, s2| duration_by_speaker(s1) <=> duration_by_speaker(s2)}.reverse end |
#type_uri ⇒ Object
116 117 118 |
# File 'lib/diarize/audio.rb', line 116 def type_uri @type_uri || 'mo:AudioFile' end |
#type_uri=(type_uri) ⇒ Object
120 121 122 |
# File 'lib/diarize/audio.rb', line 120 def type_uri=(type_uri) @type_uri = type_uri end |
#uri ⇒ Object
101 102 103 |
# File 'lib/diarize/audio.rb', line 101 def uri @uri end |
#uri=(uri) ⇒ Object
105 106 107 |
# File 'lib/diarize/audio.rb', line 105 def uri=(uri) @uri = uri end |