Home > Archive > Java Help > October 2006 > Java silence detection
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Java silence detection
|
|
| miraglia.c@gmail.com 2006-10-17, 10:00 pm |
| How to detect the "silence" in a File.wav, during recording.
Thanks.
Kar
| |
| Knute Johnson 2006-10-17, 10:00 pm |
| miraglia.c@gmail.com wrote:
> How to detect the "silence" in a File.wav, during recording.
>
> Thanks.
>
> Kar
>
During recording or in a .wav file? If you are using Java Sound to
record from your sound card you will find detecting silence problematic.
When you collect sound data with Java it is in PCM format. The values
received reflect the level of sound. Zero would be no sound and in the
case of 8 bit data, 127 or -128 would be maximum level.
The problem I think you will find is that the sound cards have fairly
high levels of noise and you will have to pick some arbitrarily high
number to assume no sound. That will then give you a relatively small
dynamic range work with.
If you are trying to find silence in a .wav file you will have to know
that format that the .wav file is actually stored in. It can be PCM but
also many other formats. I don't know a lot about .wav but I'm sure you
could find plenty of info by searching Microsoft's web sites.
--
Knute Johnson
email s/nospam/knute/
| |
| miraglia.c@gmail.com 2006-10-18, 8:00 am |
|
Knute Johnson ha scritto:
> miraglia.c@gmail.com wrote:
>
> During recording or in a .wav file? If you are using Java Sound to
> record from your sound card you will find detecting silence problematic.
> When you collect sound data with Java it is in PCM format. The values
> received reflect the level of sound. Zero would be no sound and in the
> case of 8 bit data, 127 or -128 would be maximum level.
>
> The problem I think you will find is that the sound cards have fairly
> high levels of noise and you will have to pick some arbitrarily high
> number to assume no sound. That will then give you a relatively small
> dynamic range work with.
>
> If you are trying to find silence in a .wav file you will have to know
> that format that the .wav file is actually stored in. It can be PCM but
> also many other formats. I don't know a lot about .wav but I'm sure you
> could find plenty of info by searching Microsoft's web sites.
>
>
>
> --
>
> Knute Johnson
> email s/nospam/knute/
First of all: thanks.
I collect audio data in PCM format and I found that the level of noise
is quite high.
I used a simple mathematic average like this:
if((numBytesRead= targetLine.read(data, 0, bufferLengthInBytes)) ==-1)
{break;}
somma=0;
for(int i = 800; i<20000; i+=1 ){
somma += Math.abs ( data [i]);
}
to work out a number for the thresholding. I also restricted the
frquency range because I want to find silence in speech.
What do you think about this method?
Thanks a lot.
Kar
| |
| Knute Johnson 2006-10-18, 7:07 pm |
| miraglia.c@gmail.com wrote:
> Knute Johnson ha scritto:
>
>
>
> First of all: thanks.
> I collect audio data in PCM format and I found that the level of noise
> is quite high.
> I used a simple mathematic average like this:
>
> if((numBytesRead= targetLine.read(data, 0, bufferLengthInBytes)) ==-1)
> {break;}
> somma=0;
> for(int i = 800; i<20000; i+=1 ){
> somma += Math.abs ( data [i]);
> }
>
> to work out a number for the thresholding. I also restricted the
> frquency range because I want to find silence in speech.
> What do you think about this method?
> Thanks a lot.
>
> Kar
>
Kar:
That is a good idea. I worked on silence detection for quite a while
until I figured out the noise situation. By then the project had ended
so I dropped it. I haven't tried to analyze the frequency of the sound
card noise but that sounds like a good place to start looking. If you
come up with something, please post it back here. I know I would be
very curious to see it work.
--
Knute Johnson
email s/nospam/knute/
| |
| miraglia.c@gmail.com 2006-10-19, 8:01 am |
|
Knute Johnson ha scritto:
> miraglia.c@gmail.com wrote:
[color=darkred]
> Kar:
>
> That is a good idea. I worked on silence detection for quite a while
> until I figured out the noise situation. By then the project had ended
> so I dropped it. I haven't tried to analyze the frequency of the sound
> card noise but that sounds like a good place to start looking. If you
> come up with something, please post it back here. I know I would be
> very curious to see it work.
>
> --
>
> Knute Johnson
> email s/nospam/knute/
I am not trying to analyze the sound card noise. I just want to
understand what level it has to eliminate it. I found out that with the
method I wrote before (the average) my sound card has a "somma" value
of about 20. I suppose it is quite high and I' m trying to find out a
new method that can be more accurate in the definition of the sound
card noise.
I forgot to say that speaking (without screaming) the "somma" value is
about 30.
Thank you again
Kar
| |
| Andrew Thompson 2006-10-19, 8:01 am |
| miraglia.c@gmail.com wrote:
.....
> I used a simple mathematic average like this:
>
> if((numBytesRead= targetLine.read(data, 0, bufferLengthInBytes)) ==-1)
> {break;}
> somma=0;
> for(int i = 800; i<20000; i+=1 ){
> somma += Math.abs ( data [i]);
> }
I had been meaning to ask if you had taken the format
of the data line into account. I was surprised to see that
all lines on my PC were stereo 44.1KHz - 16 bit (signed
or something).
When plotting the data, it was apparent I was making
some fundamental mistake in converting the bytes to
numbers, and my traces* 'looked like your description'.
* <http://www.physci.org/test/oscilloscope/screenshots/>
Note particularly the images prefixed with 'sinetone' -
I wanted the simplest of input signals.
Go to the parent directory for the 'audiotraces' Jar file,
the source I of it, and the small 'tone.jar' which I found
handy for testing..
BTW - please remove tab's from source before posting.
2 or four space characters is best.
Andrew T.
| |
| Knute Johnson 2006-10-19, 10:00 pm |
| miraglia.c@gmail.com wrote:
> Knute Johnson ha scritto:
>
>
>
> I am not trying to analyze the sound card noise. I just want to
> understand what level it has to eliminate it. I found out that with the
> method I wrote before (the average) my sound card has a "somma" value
> of about 20. I suppose it is quite high and I' m trying to find out a
> new method that can be more accurate in the definition of the sound
> card noise.
> I forgot to say that speaking (without screaming) the "somma" value is
> about 30.
>
> Thank you again
> Kar
>
One of my sound cards gave an average level, with 16 bit, of about 70.
It was very noisy and was very difficult to determine what was actual
signal and what was noise.
--
Knute Johnson
email s/nospam/knute/
| |
| miraglia.c@gmail.com 2006-10-19, 10:00 pm |
|
Andrew Thompson ha scritto:
> miraglia.c@gmail.com wrote:
> ....
>
> I had been meaning to ask if you had taken the format
> of the data line into account. I was surprised to see that
> all lines on my PC were stereo 44.1KHz - 16 bit (signed
> or something).
>
> When plotting the data, it was apparent I was making
> some fundamental mistake in converting the bytes to
> numbers, and my traces* 'looked like your description'.
>
> * <http://www.physci.org/test/oscilloscope/screenshots/>
> Note particularly the images prefixed with 'sinetone' -
> I wanted the simplest of input signals.
>
> Go to the parent directory for the 'audiotraces' Jar file,
> the source I of it, and the small 'tone.jar' which I found
> handy for testing..
>
> BTW - please remove tab's from source before posting.
> 2 or four space characters is best.
>
> Andrew T.
No, I hadn't taken in account the format of the data line.
I just read the sound data from the targetDataLine and
converted every single byte (they are 44100) from the line
in a number. I suppose that when this number was near to
0...it was silence. But I discovered that these values are,
in a lot of cases, very far from 0. This is why I introduced
the average.
All lines on my PC are 44.1 KHz 16 bit PCM_SIGNED too (I
found out these infos from your "audiotraces.jar").
I executed your application and I can't understand why
did you write "I was making some fundamental mistake in converting
the bytes to numbers". I think your traces are good. I just
understood that reading from the line produces an array of
byte of 44100 elements. Every one of them is a frequency.
But I am not able to understand nothing about the number of
channels (stereo).
Fortunately for me, I'm not interested in distinguish the
actual signal from noise. I just want to detect silence
to stop recording (acquiring sound data).
I hope my post will be useful for you.
Kar
| |
| Andrew Thompson 2006-10-20, 4:11 am |
| miraglia.c@gmail.com wrote:
> Andrew Thompson ha scritto:
>
....[color=darkred]
> No, I hadn't taken in account the format of the data line.
> I just read the sound data from the targetDataLine and
> converted every single byte (they are 44100) from the line
> in a number. I suppose that when this number was near to
> 0...it was silence.
If it is 16 bit - that assumption is wrong.
I'll try again..
<http://www.physci.org/test/oscilloscope/screenshots/>
Look particularly at ..'sinetoneallbytes-b.png'* - do you
notice the red/yellow traces? Do they appear to be 'noise'?
*
<http://www.physci.org/test/oscillos...eallbytes-b.png>
Andrew T.
| |
| Andrew Thompson 2006-10-20, 4:11 am |
| Knute Johnson wrote:
....
.....[color=darkred]
> One of my sound cards gave an average level, with 16 bit, of about 70.
> It was very noisy ...
Is that '70 out of 128' or '70 out of 32,678'? The first
would make that sound card like a 'crackly phone'
...no, worse like 'trying to listen to a faint radio signal
in a thunderstorm', whereas I cannot see that
70/32,678 constitutes 'very noisy'.
>....and was very difficult to determine what was actual
> signal and what was noise.
I would particularly like your* perspective on what I am
saying about the small order bytes (of a 16 bit signal).
I think they are throwing out the calculation and producing
erroneous numbers, indicating a higher level of noise
than actually exists. Have a look at the yellow/red
trace in the screenshot I linked to - they are traces of
the small order byte (the large order bytes, form the
green/purple sinusoidal traces)..
* Your posts suggest a widespread understanding
of computing/images/sounds. In fact, that 'tone.jar'
shown in the image I linked to, is loosely based on
this source you posted!
<http://groups.google.com/group/comp...cba0ba9e4c38144>
( + I am not sure I am yet communicating myself well,
and am hoping you can understand what I am trying
to get across..)
Andrew T.
| |
| Knute Johnson 2006-10-20, 7:04 pm |
| Andrew Thompson wrote:
> Knute Johnson wrote:
> ...
> ....
>
> Is that '70 out of 128' or '70 out of 32,678'? The first
> would make that sound card like a 'crackly phone'
> ..no, worse like 'trying to listen to a faint radio signal
> in a thunderstorm', whereas I cannot see that
> 70/32,678 constitutes 'very noisy'.
Yes, 70 out of 32,768. Since voice signals from the microphone peaked
in the 200s it was very difficult to detect silence.
>
> I would particularly like your* perspective on what I am
> saying about the small order bytes (of a 16 bit signal).
>
> I think they are throwing out the calculation and producing
> erroneous numbers, indicating a higher level of noise
> than actually exists. Have a look at the yellow/red
> trace in the screenshot I linked to - they are traces of
> the small order byte (the large order bytes, form the
> green/purple sinusoidal traces)..
>
> * Your posts suggest a widespread understanding
> of computing/images/sounds. In fact, that 'tone.jar'
> shown in the image I linked to, is loosely based on
> this source you posted!
> <http://groups.google.com/group/comp...cba0ba9e4c38144>
> ( + I am not sure I am yet communicating myself well,
> and am hoping you can understand what I am trying
> to get across..)
>
> Andrew T.
>
Correct me if I am wrong but you are saying that the nice clean sine
waves are just the higher order bits? And the noisy looking yellow and
red lines are the low order bits?
If that is the case, masking off the low order bits would seem to be a
really simple way to eliminate most of the sound card noise.
--
Knute Johnson
email s/nospam/knute/
| |
| Andrew Thompson 2006-10-20, 7:04 pm |
| Knute Johnson wrote:
> Andrew Thompson wrote:
>
> Yes, 70 out of 32,768. Since voice signals from the microphone peaked
> in the 200s it was very difficult to detect silence.
Wow! 200 out of 32,678 is very quiet!
> Correct me if I am wrong but you are saying that the nice clean sine
> waves are just the higher order bits? And the noisy looking yellow and
> red lines are the low order bits?
Yes... but now I think about it, I am not too sure if I
used some sort of scaling factor to accentuate it - I
am pretty sure that is a direct 1-1 trace (of both high
& low order bits ranging from 0-256) ..now I'm not sure
I understand what you are asking..
> If that is the case, masking off the low order bits would seem to be a
> really simple way to eliminate most of the sound card noise.
....I am not entirely sure yet (of anything).
Could you indulge me by having a play with the latest
AudioTrace source?*
Tonight (mostly out of curiousity) I added a little 'level meter'
on the lower right, and it can also show a textual equivalent
in the upper right (see bottom of first config. screen to show/hide).
It shows the level, which supposedly ranges from 0-256.
It paints a faint ..
- white background if the level is above .5.
- yellow bg if the level is above .01.
- red bg otherwise.
...on top it paints a pale green bar to show the current level.
Here I am regularly seeing the level go above half way,
it will drop into yellow for very quiet sections of songs,
and only drop to red between songs.
Would you (both y'all and anyone else willing to test it)
say those results describe what you are seeing in your
system(s)?
If not, play with the numbers a bit, and see if it works
better for you.
I'm afraid the source is more 'hacked together' than
'carefully crafted' - especially these last changes - but
it should still be fairly logical (crosses fingers).
* Oh yeah - I also uploaded the new 'audiotrace.jar'
made from the latest source - note that the older
'audiotraceS.jar' is still there as well.
Andrew T.
| |
| Knute Johnson 2006-10-20, 7:04 pm |
| Andrew Thompson wrote:
> Knute Johnson wrote:
>
> Wow! 200 out of 32,678 is very quiet!
>
>
> Yes... but now I think about it, I am not too sure if I
> used some sort of scaling factor to accentuate it - I
> am pretty sure that is a direct 1-1 trace (of both high
> & low order bits ranging from 0-256) ..now I'm not sure
> I understand what you are asking..
>
>
> ...I am not entirely sure yet (of anything).
>
> Could you indulge me by having a play with the latest
> AudioTrace source?*
>
> Tonight (mostly out of curiousity) I added a little 'level meter'
> on the lower right, and it can also show a textual equivalent
> in the upper right (see bottom of first config. screen to show/hide).
>
> It shows the level, which supposedly ranges from 0-256.
> It paints a faint ..
> - white background if the level is above .5.
> - yellow bg if the level is above .01.
> - red bg otherwise.
> ..on top it paints a pale green bar to show the current level.
>
> Here I am regularly seeing the level go above half way,
> it will drop into yellow for very quiet sections of songs,
> and only drop to red between songs.
>
> Would you (both y'all and anyone else willing to test it)
> say those results describe what you are seeing in your
> system(s)?
>
> If not, play with the numbers a bit, and see if it works
> better for you.
>
> I'm afraid the source is more 'hacked together' than
> 'carefully crafted' - especially these last changes - but
> it should still be fairly logical (crosses fingers).
>
> * Oh yeah - I also uploaded the new 'audiotrace.jar'
> made from the latest source - note that the older
> 'audiotraceS.jar' is still there as well.
Where is there? I must have missed a link somewhere.
--
Knute Johnson
email s/nospam/knute/
| |
|
|
| Andrew Thompson 2006-10-21, 8:01 am |
| Andrew Thompson wrote:
> Knute Johnson wrote:
> ....
>
> <http://www.physci.org/test/oscilloscope/>
Oops! My hackish source came back to bite me
in the buttock..
I noticed the level meter was changing depending on the
'Sample Size'. After some further investigation I fixed the
problem and those figures of relevance are..
- The level meter registers between 0 & 1
- Below .0005 it paints yellow BG.
- Below .0002 it paints red BG - 'no signal'.
(Uploaded the new jar 'audiotrace.jar' & source a
few minutes ago)
Andrew T.
|
|
|
|
|