1 | ######################################################################
|
---|
2 | #
|
---|
3 | # AudioPlugin.pm -- plugin for processing video largely based on ImagePlug
|
---|
4 | # A component of the Greenstone digital library software
|
---|
5 | # from the New Zealand Digital Library Project at the
|
---|
6 | # University of Waikato, New Zealand.
|
---|
7 | #
|
---|
8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or modify
|
---|
11 | # it under the terms of the GNU General Public License as published by
|
---|
12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
13 | # (at your option) any later version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful,
|
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | # GNU General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, write to the Free Software
|
---|
22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | #
|
---|
24 | ###########################################################################
|
---|
25 |
|
---|
26 | package StructuredAudioPlugin;
|
---|
27 |
|
---|
28 | use strict;
|
---|
29 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
30 | no strict 'subs';
|
---|
31 |
|
---|
32 | use gsprintf;
|
---|
33 | use FileUtils;
|
---|
34 |
|
---|
35 | use AudioPlugin;
|
---|
36 |
|
---|
37 |
|
---|
38 | sub BEGIN {
|
---|
39 | @StructuredAudioPlugin::ISA = ('AudioPlugin');
|
---|
40 | }
|
---|
41 |
|
---|
42 | my $arguments =
|
---|
43 | [ { 'name' => "segment_audio",
|
---|
44 | 'desc' => "{StructuredAudioPlugin.segment_audio}",
|
---|
45 | 'type' => "flag",
|
---|
46 | 'reqd' => "no" }
|
---|
47 | ];
|
---|
48 |
|
---|
49 | my $options = { 'name' => "StructuredAudioPlugin",
|
---|
50 | 'desc' => "{StructuredAudioPlugin.desc}",
|
---|
51 | 'abstract' => "no",
|
---|
52 | 'inherits' => "yes",
|
---|
53 | 'args' => $arguments };
|
---|
54 |
|
---|
55 |
|
---|
56 | sub new {
|
---|
57 | my ($class) = shift (@_);
|
---|
58 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
59 | push(@$pluginlist, $class);
|
---|
60 |
|
---|
61 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
62 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
63 |
|
---|
64 | my $self = new AudioPlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
65 |
|
---|
66 | return bless $self, $class;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | sub begin {
|
---|
71 | my $self = shift (@_);
|
---|
72 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
73 |
|
---|
74 | $self->SUPER::begin(@_);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | sub init {
|
---|
79 | my $self = shift (@_);
|
---|
80 | my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
81 |
|
---|
82 | $self->SUPER::init(@_);
|
---|
83 |
|
---|
84 | my @pyannote_monitor = ( 'monitor_init' , "MultimediaConverter::unbuffered_monitor_init",
|
---|
85 | 'monitor_line' , "StructuredAudioPlugin::pyannote_monitor_line",
|
---|
86 | 'monitor_deinit' , "MultimediaConverter::unbuffered_monitor_deinit" );
|
---|
87 |
|
---|
88 | $self->{'pyannote_monitor'} = \@pyannote_monitor;
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | sub pyannote_monitor_line
|
---|
93 | {
|
---|
94 | my ($line) = @_;
|
---|
95 |
|
---|
96 | my $had_error = 0;
|
---|
97 | my $generate_dot = 0;
|
---|
98 |
|
---|
99 | if ($line =~ m/^.*$/)
|
---|
100 | {
|
---|
101 | $generate_dot = 1;
|
---|
102 | }
|
---|
103 |
|
---|
104 | return ($had_error,$generate_dot);
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | sub run_convert {
|
---|
111 | my $self = shift (@_);
|
---|
112 | my ($base_dir,$filename,$file,$doc_obj) = @_;
|
---|
113 |
|
---|
114 | my $section = $doc_obj->get_top_section();
|
---|
115 |
|
---|
116 | my $verbosity = $self->{'verbosity'};
|
---|
117 | my $outhandle = $self->{'outhandle'};
|
---|
118 |
|
---|
119 | $self->SUPER::run_convert(@_);
|
---|
120 |
|
---|
121 | if ($self->{'segment_audio'}) {
|
---|
122 |
|
---|
123 | $self->init_cache_for_file($filename);
|
---|
124 | my $cached_audio_dir = $self->{'cached_dir'};
|
---|
125 | # my $audio_root = $self->{'cached_file_root'};
|
---|
126 |
|
---|
127 | # my $filename_no_path = &File::Basename::basename($filename);
|
---|
128 |
|
---|
129 | my $ofile = "structured-audio.csv";
|
---|
130 | my $ofilename = &FileUtils::filenameConcatenate($cached_audio_dir,"structured-audio.csv");
|
---|
131 | my $pyannote_cmd = "diarization.py \"$filename\" \"$ofilename\"";
|
---|
132 |
|
---|
133 | my $pyannote_regenerated;
|
---|
134 | my $pyannote_result;
|
---|
135 | my $pyannote_error;
|
---|
136 |
|
---|
137 | my $pyannote_options = { @{$self->{'pyannote_monitor'}},
|
---|
138 | 'message_prefix' => "pyannote",
|
---|
139 | 'message' => "Segmenting audio" };
|
---|
140 |
|
---|
141 | ($pyannote_regenerated,$pyannote_result,$pyannote_error)
|
---|
142 | = $self->run_cached_general_cmd($pyannote_cmd,$filename,$ofilename,$pyannote_options);
|
---|
143 |
|
---|
144 | $doc_obj->associate_file($ofilename,$ofile,"text/csv",$section);
|
---|
145 |
|
---|
146 | }
|
---|
147 |
|
---|
148 | return "csv";
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | 1;
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|