-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_sound.pl
176 lines (153 loc) · 4.21 KB
/
test_sound.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/perl
##
# File : test_sounds.pl
# Date : 23/10/2012
# Author : spjspj
# Purpose : Allow the recorder to just keep recording!
##
use strict;
my $file_name;
my $search1;
my $search2;
my $search3;
my $search4;
# Quiescent RMS - amplitude
my $q_max_amplitude = 0.04;
my $rms_amplitude_seen_min = 1.0;
my $sound_file_num = 0;
my $zip_file_num = 0;
sub rename_new_sound
{
my $existing_file = $_ [0];
my $d = `date '+%Y%m%d%H%M%S'`;
chomp $d;
my $sub = "rns_" . $d;
$sub =~ s/\W/_/g;
$sub =~ s/__/_/g;
$sub =~ s/__/_/g;
$sub =~ s/__/_/g;
$sub .= "_$sound_file_num.wav";
$sound_file_num++;
print ("Rename: mv $existing_file /home_monitor/Spool/$sub\n");
`mv "$existing_file" "/home_monitor/Spool/$sub"`;
print ("DONE Rename: mv $existing_file /home_monitor/Spool/$sub\n");
return "/home_monitor/Spool/$sub";
}
sub zip_sounds
{
my $d = `date '+%Y%m%d%H%M%S'`;
chomp $d;
my $c = `ls -1 /home_monitor/Archive/*wav | wc -l`;
chomp $c;
if ($c < 100)
{
print ("Am seeing not enough $c .wav files!\n");
return;
}
my $sub = "linux_sounds_" . $d;
$sub =~ s/\W/_/g;
$sub =~ s/__/_/g;
$sub =~ s/__/_/g;
$sub =~ s/__/_/g;
$sub .= ".zip";
$zip_file_num++;
print ("Rename: Making zip file of $sub\n");
`zip /home_monitor/Archive/LOUD_$sub /home_monitor/Archive/*LOUD.wav`;
`rm -f /home_monitor/Archive/*LOUD.wav`;
`zip /home_monitor/Archive/LOUD_MOD_$sub /home_monitor/Archive/*LOUD.wav`;
`rm -f /home_monitor/Archive/*LOUD_MOD.wav`;
`zip /home_monitor/Archive/$sub /home_monitor/Archive/*LOUD.wav`;
`rm -f /home_monitor/Archive/*.wav`;
}
my $num_times = 0;
sub test_sound
{
my $sub = $_ [0];
my $test_str = "sox $sub -n stat 2>&1 |";
my $max_amplitude = -500;
open PROC, $test_str;
while (<PROC>)
{
chomp;
if ($_ =~ m/Maximum.*amplitude.*?(\d+\.\d+)/i)
{
$max_amplitude = $1;
}
}
close PROC;
$num_times++;
if ($num_times > 100)
{
$num_times = 0;
}
my $arch_dir = "/home_monitor/Archive/";
if ($max_amplitude >= $q_max_amplitude)
{
my $new_sub = $sub;
my $new_sub2 = $new_sub;
$new_sub =~ s/.*\///;
$new_sub2 =~ s/.*\///;
$new_sub = "/home_monitor/Spool/$new_sub.rmsa.$max_amplitude";
my $arch_file = "$arch_dir$new_sub2";
$arch_file = "$arch_file.RMSA.$max_amplitude";
if ($max_amplitude >= 0.15)
{
print ("mv $sub $new_sub.LOUD.wav\n");
`cp $sub $arch_file.LOUD.wav`;
`mv $sub $new_sub.LOUD.wav`;
return 1;
}
elsif ($max_amplitude >= 0.08)
{
print ("mv $sub $new_sub.LOUD_MOD.wav\n");
`cp $sub $arch_file.LOUD_MOD.wav`;
`mv $sub $new_sub.LOUD_MOD.wav`;
return 1;
}
else
{
print ("mv $sub $new_sub.wav\n");
`cp $sub $arch_file.wav`;
`rm $sub`;
return 1;
}
}
else
{
print ("NoKeep:$sub (Rms_amp=$max_amplitude v $q_max_amplitude)\n");
`rm $sub`;
return 0;
}
}
# Main
{
my $file;
print ("Running $0 right now!\n");
while (1)
{
{
# Do sound testing for /home_monitor/pool/.wav
my @record_now_file;
opendir (DIR, "/home_monitor/Spool/");
@record_now_file = grep { /AA.*wav/ } readdir (DIR);
closedir DIR;
$file = "";
foreach $file (@record_now_file)
{
print ("\n\n--------------------->> Looking at $file now\n");
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat ("/home_monitor/Spool/$file");
if (time - $mtime > 5)
{
print ($mtime, " -- $file\n");
# Keep and/or delete!
$file = "/home_monitor/Spool/$file";
$file = rename_new_sound ($file);
test_sound ($file);
}
}
sleep (1);
}
zip_sounds ();
sleep (15);
}
}