Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check if .wav is silent or not
#1
Hi Gintaras,

I was wondering (I've had a look around and can't see anything immediately) if it was possible to create something that can analyze a .wav file to see if it is completely silent or contains any noise/voice at all. I'd need my program to listen to a .wav file through a player which is ran inside a web page. It would be possible to extract the .wav if absolute necessary but this function/macro will be analyzing hundreds (possibly thousands of .wavs a week so want to avoid having to extract at all.

Apologies if this has already been asked somewhere else but I really couldn't find anything.

Thanks in advance.
#2
QM does not have such functions.
#3
Function Function3
Code:
Select All      Help
str s1.getfile("C:\noise.wav")
str s2.getfile("C:\silence.wav")

outb s1 100
outb s2 100

Noise file outputs this:
Code:
Select All      Help
52 49 46 46 C4 EA 1A 00 57 41 56 45 66 6D 74 20 10 00 00 00 01 00 02 00 44 AC 00 00 10 B1 02 00 04 00 10 00 64 61 74 61 A0 EA 1A 00 C9 07 75 06 FB FE CB FA 5E 04 45 FB 33 09 44 09 EA 00 C6 05 95 05 8B F1 BB 0B E0 F1 A1 05 57 FF A5 06 6B F3 F1 02 C8 12 29 07 A2 07 9A 01 88 0E 89 FC 74 13 16 06 97 05

Silent file outputs this:
Code:
Select All      Help
52 49 46 46 C4 EA 1A 00 57 41 56 45 66 6D 74 20 10 00 00 00 01 00 02 00 44 AC 00 00 10 B1 02 00 04 00 10 00 64 61 74 61 A0 EA 1A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

I'm not quite sure how to load the hex into a variable and analyze with qm, but silent is all zeros where noise has values assigned.  The forum won't let me upload the .wav files I used.

The other way you could do it is by using SoX http://sox.sourceforge.net/

Function Function2
Code:
Select All      Help
RunConsole2("C:\Program Files\sox\sox.exe C:\silence.wav -n stat" str'sout)
out sout

RunConsole2("C:\Program Files\sox\sox.exe C:\noise.wav -n stat" sout)
out sout


str pattern="Mean\s*amplitude:\s*(.*)"
str MeanAmp
findrx(sout pattern 0 0 MeanAmp 1)
out MeanAmp
if val(MeanAmp 2)
,out "NOT SILENT"
#4
Hi TheVig,

For Function3 we could do something like this using QM:

Function CheckSilentWav
Code:
Select All      Help
str wavFile1="C:\Temp\noise.wav"
str wavFile2="C:\Temp\silence.wav"

;Read in data from wav files
str s1.getfile(wavFile1)
str s2.getfile(wavFile2)

;Convert binary data to string array, just extract 50 bytes only.
ARRAY(str) a1 a2
sub.GetDataFile(s1 50 a1)
sub.GetDataFile(s2 50 a2)

;Check for silent wavFile1
int result=sub.CheckSilentWav(a1)
if(result) out F"{wavFile1} is silent."
else if(result=0) out F"{wavFile1} is noisy."
else out F"Unknown {wavFile1} file."

;Check for silent wavFile2
result=sub.CheckSilentWav(a2)
if(result) out F"{wavFile2} is silent."
else if(result=0) out F"{wavFile2} is noisy."
else out F"Unknown {wavFile2} file."

#sub GetDataFile
function !*ptr nBytes ARRAY(str)&a

_s.encrypt(8 _s.fromn(ptr nBytes) "" 1)
_s.findreplace(" ", "[]", 8)
a=_s

#sub CheckSilentWav
function# ARRAY(str)&wav
;Note1: return 1 if wav file is silent; return 0 if wav file is noisy; otherwise return -1.
;Note2: just check the value from 44th to 50th position (7 bytes only) to find out if it is silence or not.
if wav.len > 0
,for _i 43 50
,,if(!(StrCompare(wav[_i], "00")=0)) ret 0
,ret 1
else
,ret -1


Attached Files
.zip   noise.zip (Size: 5.86 KB / Downloads: 15)
.zip   silence.zip (Size: 396 bytes / Downloads: 16)


Forum Jump:


Users browsing this thread: 1 Guest(s)