[22323] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # jAudioConverter - helper plugin that does office document conversion
|
---|
| 4 | # using jodconverter combined with MIR
|
---|
| 5 | #
|
---|
| 6 | # A component of the Greenstone digital library software
|
---|
| 7 | # from the New Zealand Digital Library Project at the
|
---|
| 8 | # University of Waikato, New Zealand.
|
---|
| 9 | #
|
---|
| 10 | # Copyright (C) 2010 New Zealand Digital Library Project
|
---|
| 11 | #
|
---|
| 12 | # This program is free software; you can redistribute it and/or modify
|
---|
| 13 | # it under the terms of the GNU General Public License as published by
|
---|
| 14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | # (at your option) any later version.
|
---|
| 16 | #
|
---|
| 17 | # This program is distributed in the hope that it will be useful,
|
---|
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | # GNU General Public License for more details.
|
---|
| 21 | #
|
---|
| 22 | # You should have received a copy of the GNU General Public License
|
---|
| 23 | # along with this program; if not, write to the Free Software
|
---|
| 24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | #
|
---|
| 26 | ###########################################################################
|
---|
| 27 | package jAudioConverter;
|
---|
| 28 |
|
---|
| 29 | use BaseMediaConverter;
|
---|
| 30 |
|
---|
| 31 | use strict;
|
---|
| 32 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 33 |
|
---|
| 34 | use gsprintf 'gsprintf';
|
---|
| 35 |
|
---|
| 36 | BEGIN {
|
---|
| 37 | @jAudioConverter::ISA = ('BaseMediaConverter');
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | my $arguments = [
|
---|
| 42 | { 'name' => "window_size",
|
---|
| 43 | 'desc' => "{jAudioConverter.window_size}",
|
---|
| 44 | 'type' => "int",
|
---|
| 45 | 'range' => "128,",
|
---|
| 46 | 'deft' => '512',
|
---|
| 47 | 'reqd' => "no" },
|
---|
| 48 | { 'name' => "window_overlap",
|
---|
| 49 | 'desc' => "{jAudioConverter.window_overlap}",
|
---|
| 50 | 'type' => "string",
|
---|
| 51 | 'range' => "0.0",
|
---|
| 52 | 'deft' => '0.0',
|
---|
| 53 | 'reqd' => "no" },
|
---|
| 54 | { 'name' => "sample_rate",
|
---|
| 55 | 'desc' => "{jAudioConverter.sample_rate}",
|
---|
| 56 | 'type' => "enum",
|
---|
| 57 | 'list' => [{'name' => "8 kHz", 'desc' => "{jAudioConverter.8000Hz}"},
|
---|
| 58 | {'name' => "11.025 kHz", 'desc' => "{jAudioConverter.11025Hz}"},
|
---|
| 59 | {'name' => "16 kHz", 'desc' => "{jAudioConverter.16000Hz}"},
|
---|
| 60 | {'name' => "22.05 kHz", 'desc' => "{jAudioConverter.22050Hz}"},
|
---|
| 61 | {'name' => "44.1 kHz", 'desc' => "{jAudioConverter.44100Hz}"} ],
|
---|
| 62 | 'deft' => '16 kHz',
|
---|
| 63 | 'reqd' => "no" },
|
---|
| 64 | { 'name' => "extracted_data",
|
---|
| 65 | 'desc' => "{jAudioConverter.extracted_data}",
|
---|
| 66 | 'type' => "enum",
|
---|
| 67 | 'list' => [{'name' => "Overall and Windowed", 'desc' => "{jAudioConverter.overall_and_windowed}"},
|
---|
| 68 | {'name' => "Windowed only", 'desc' => "{jAudioConverter.windowed_only}"},
|
---|
| 69 | {'name' => "Overall only", 'desc' => "{jAudioConverter.overall_only}"}],
|
---|
| 70 | 'deft' => 'Overall and Windowed',
|
---|
| 71 | 'reqd' => "no" },
|
---|
| 72 | { 'name' => "output_type",
|
---|
| 73 | 'desc' => "{jAudioConverter.output_type}",
|
---|
| 74 | 'type' => "enum",
|
---|
| 75 | 'list' => [{'name' => "ACE XML", 'desc' => "{jAudioConverter.ace_xml}"},
|
---|
| 76 | {'name' => "Weka ARFF", 'desc' => "{jAudioConverter.weka_arff}"}],
|
---|
| 77 | 'deft' => 'ACE XML',
|
---|
| 78 | 'reqd' => "no" }
|
---|
| 79 | ];
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | my $options = { 'name' => "jAudioConverter",
|
---|
| 84 | 'desc' => "{jAudioConverter.desc}",
|
---|
| 85 | 'abstract' => "yes",
|
---|
| 86 | 'inherits' => "yes",
|
---|
| 87 | 'args' => $arguments };
|
---|
| 88 |
|
---|
| 89 | sub new {
|
---|
| 90 | my ($class) = shift (@_);
|
---|
| 91 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 92 | push(@$pluginlist, $class);
|
---|
| 93 |
|
---|
| 94 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 95 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
| 96 |
|
---|
| 97 | my $self = new BaseMediaConverter($pluginlist, $inputargs, $hashArgOptLists, 1);
|
---|
| 98 |
|
---|
| 99 | return bless $self, $class;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | sub convert {
|
---|
| 104 | my $self = shift(@_);
|
---|
| 105 | my $source_file_path = shift(@_);
|
---|
| 106 | my $target_file_type = shift(@_);
|
---|
| 107 | my $convert_options = shift(@_) || "";
|
---|
| 108 | my $convert_id = shift(@_) || "";
|
---|
| 109 | my $cache_mode = shift(@_) || "";
|
---|
| 110 |
|
---|
| 111 | my $outhandle = $self->{'outhandle'};
|
---|
| 112 | my $verbosity = $self->{'verbosity'};
|
---|
| 113 |
|
---|
| 114 | my $source_file_no_path = &File::Basename::basename($source_file_path);
|
---|
| 115 |
|
---|
| 116 | # Determine the full name and path of the output file
|
---|
| 117 | my $target_file_path;
|
---|
| 118 | if ($self->{'enable_cache'}) {
|
---|
| 119 | my $cached_dir = $self->{'cached_dir'};
|
---|
| 120 | my $file_root = $self->{'cached_file_root'};
|
---|
| 121 | $file_root .= "_$convert_id" if ($convert_id ne "");
|
---|
| 122 | my $audio_file = "$file_root.$target_file_type";
|
---|
| 123 | $target_file_path = &util::filename_cat($cached_file_dir,$audio_file);
|
---|
| 124 | }
|
---|
| 125 | else {
|
---|
| 126 | $target_file_path = &util::get_tmp_filename($target_file_type);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | my jar_home = &util::filename_cat($ENV{'GEXT_MUSICIR'},"lib","java");
|
---|
| 131 | my $jaudio_jar = &util::filename_cat($jar_home,"jAudio.jar");
|
---|
| 132 |
|
---|
| 133 | # Generate and run the convert command
|
---|
| 134 | my $convert_command = "java -jar $jaudio_jar $convert_options \"$source_file_path\" \"$target_file_path\"";
|
---|
| 135 |
|
---|
| 136 | my $print_info = { 'message_prefix' => $convert_id,
|
---|
| 137 | 'message' => "Converting $source_file_no_path to: $convert_id $target_file_type" };
|
---|
| 138 | $print_info->{'cache_mode'} = $cache_mode if ($cache_mode ne "");
|
---|
| 139 |
|
---|
| 140 | my ($regenerated,$result,$had_error)
|
---|
| 141 | = $self->autorun_general_cmd($convert_command,$target_file_path,$print_info);
|
---|
| 142 |
|
---|
| 143 | return ($result,$target_file_path);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | sub convert_without_result {
|
---|
| 147 | my $self = shift(@_);
|
---|
| 148 |
|
---|
| 149 | my $source_file_path = shift(@_);
|
---|
| 150 | my $target_file_type = shift(@_);
|
---|
| 151 | my $convert_options = shift(@_) || "";
|
---|
| 152 | my $convert_id = shift(@_) || "";
|
---|
| 153 |
|
---|
| 154 | return $self->convert($source_file_path,$target_file_type,
|
---|
| 155 | $convert_options,$convert_id,"without_result");
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 | 1;
|
---|