Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #48: bad ether in the cables


comp / comp.lang.python / Re: How to check whether audio bytes contain empty noise or actual voice/signal?

SubjectAuthor
* How to check whether audio bytes contain empty noise or actual voice/signal?marc nicole
+* Re: How to check whether audio bytes contain empty noise or actual voice/signal?Stefan Ram
|`- Re: How to check whether audio bytes contain empty noise or actual voice/signal?Stefan Ram
`- Re: How to check whether audio bytes contain empty noise or actual voice/signal?Stefan Ram

1
Subject: How to check whether audio bytes contain empty noise or actual voice/signal?
From: marc nicole
Newsgroups: comp.lang.python
Date: Fri, 25 Oct 2024 16:25 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: mk1853387@gmail.com (marc nicole)
Newsgroups: comp.lang.python
Subject: How to check whether audio bytes contain empty noise or actual
voice/signal?
Date: Fri, 25 Oct 2024 18:25:19 +0200
Lines: 31
Message-ID: <mailman.48.1729873488.4695.python-list@python.org>
References: <CAGJtH9TqEpGjQi+KYNrSV3+UtVO-jjFLK02N9MEA0uuQvr11qQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de eWMiKShX2bv9RTG0NqvgVAhVSOFpx0boQKs8cFQ8DsWg==
Cancel-Lock: sha1:iXF27Zs0yf/VU2e/avDvlfHcCxs= sha256:V030QieErH2qDyOAU7xoDyvn+YQl+tCzFMWB4Y0x/+U=
Return-Path: <mk1853387@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=jigiznyM;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.102
X-Spam-Level: *
X-Spam-Evidence: '*H*': 0.80; '*S*': 0.01; 'stream': 0.04;
'containing': 0.05; 'variable': 0.05; 'filled': 0.09; '1024':
0.16; 'mic': 0.16; 'noise': 0.16; 'python': 0.16; 'to:addr:python-
list': 0.20; 'to:no real name:2**1': 0.22; 'list,': 0.24;
'actual': 0.25; '<pre': 0.26; 'follows:': 0.26; 'sfxlen:2': 0.31;
'subject:How': 0.31; 'message-id:@mail.gmail.com': 0.31;
'question': 0.32; 'empty': 0.32; 'but': 0.32; 'there': 0.33;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.34; 'main':
0.37; 'using': 0.37; 'hard': 0.37; 'way': 0.38; 'finding': 0.39;
'want': 0.40; 'skip:i 20': 0.62; 'format': 0.62; 'rate': 0.67;
'collect': 0.69; 'voice': 0.69; 'audio': 0.70; 'skip:f 30': 0.71;
'<span': 0.76; 'significant': 0.78; 'signals': 0.84;
'subject:voice': 0.84; 'channels': 0.91; 'somebody': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1729873485; x=1730478285; darn=python.org;
h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
:date:message-id:reply-to;
bh=/TtregYyrXi/erlgMqYdExerNAqBFlLhHFr3aTLvORA=;
b=jigiznyMAKwKBLiwzQC9u1Ju3t/g762kQYF+f/cMYXmX2urOTt75P5xiHiUvC4zG6N
Xwg1mUpcTrmOKmaznQJe86wnNZLtCGCEQvaWq1Vji4lXXj77hW6i0k44iTkDPWgSPoOk
ewHQoaEsFueV5eipJHre06Apcw7CPfay3UENJZjf9X9cF+YtvYMlsd3LzKLSi1DbyFdr
ZqecO1O0DsLZq6zjIhTqkHMm04iR27jVVyiRSPCcrRTkEu5c8Hv5B8Yr27FgqGmEhfIJ
JpyVS2mkeY2QNUVue2A+RHwRNDx9Gxjwcus1LFJLH2uIFKDjVsPY/CLa/SoSU6j2ecok
Or3w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1729873485; x=1730478285;
h=to:subject:message-id:date:from:mime-version:x-gm-message-state
:from:to:cc:subject:date:message-id:reply-to;
bh=/TtregYyrXi/erlgMqYdExerNAqBFlLhHFr3aTLvORA=;
b=fMa54ko6cOCnJ+JP4Di1sjnb99PPRqOC7mJDnD5tdiDphw/WM1PHORVNVHHsT2ErXm
dwjYhIeGx/uE7NDar6u1GfRkMvJ5TybBg6WQ6RK9OpHDN3FHelJLXsGa5YwjLx8ayQw8
qCgYeLYxZ0zNWS9YdY0vDd4CnWTWp/4j9qyZl6PwoTEviDX8WK+caqNBRwKylVq6Fdgd
ZSHUZiQn76mDDbI32Sele9Vxl18SmUrciPkie0bcU6tADXBSnGqZyjN7kZ0AMCcXbo28
H2JE90zkIX0DE1vRDq2mTXx7PjEjv4Hsdes4DGMjZ8VNZJ7r/iPfxRERvZXGcYRG0Oao
aStw==
X-Forwarded-Encrypted: i=1;
AJvYcCWwp9QUzzkejEzGQOJr18DC27oiceC46jHsZ15tq+ArSinQ34BvPvUvnELvd1HttPiCr/h5M1sncZMVJw==@python.org
X-Gm-Message-State: AOJu0YwI08I6GIQtx02qjFXR7iDdRAffpZlZdJDcT8FuAq2GXDxR1k8w
nBFTxmccJj158BVRk0KAtL+eiW+bA3+LgDjCVYUbQAoYBXHfiZe+wBwRSmzvVMo9YgOdIlcgZ94
YXNwkQxQnlP6wsQp+m2ymPFsHu1qDsi0p
X-Google-Smtp-Source: AGHT+IFor2K8THA3tCSxcFu4McLKjRUEpSarc8TDjELWTqn9xymFucZMAV1STCQdEeL2WNgrG7/BqBbyLfk12WRtjX4=
X-Received: by 2002:a05:690c:102:b0:6e2:12e5:35b4 with SMTP id
00721157ae682-6e9d87bce9cmr1427507b3.0.1729873485148; Fri, 25 Oct 2024
09:24:45 -0700 (PDT)
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAGJtH9TqEpGjQi+KYNrSV3+UtVO-jjFLK02N9MEA0uuQvr11qQ@mail.gmail.com>
View all headers

Hello Python fellows,

I hope this question is not very far from the main topic of this list, but
I have a hard time finding a way to check whether audio data samples are
containing empty noise or actual significant voice/noise.

I am using PyAudio to collect the sound through my PC mic as follows:

FRAMES_PER_BUFFER = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 48000
RECORD_SECONDS = 2import pyaudio
audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=FRAMES_PER_BUFFER,
input_device_index=2)
data = stream.read(FRAMES_PER_BUFFER)

I want to know whether or not data contains voice signals or empty sound,
To note that the variable always contains bytes (empty or sound) if I print
it.

Is there an straightforward "easy way" to check whether data is filled with
empty noise or that somebody has made noise/spoke?

Thanks.

Subject: Re: How to check whether audio bytes contain empty noise or actual voice/signal?
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Fri, 25 Oct 2024 16:43 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: How to check whether audio bytes contain empty noise or actual voice/signal?
Date: 25 Oct 2024 16:43:11 GMT
Organization: Stefan Ram
Lines: 31
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <noise-20241025174236@ram.dialup.fu-berlin.de>
References: <CAGJtH9TqEpGjQi+KYNrSV3+UtVO-jjFLK02N9MEA0uuQvr11qQ@mail.gmail.com> <mailman.48.1729873488.4695.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de jvhDOWm/P4B5ZUBLguC+/wHCx14UWSxZqWI8uzrTLzuW4A
Cancel-Lock: sha1:x5ArkzpHqMyDSc5HqV842/KNA8k= sha256:1cERKZnEiOpEiQRUFUzHbHkLM+ElPDqNdg7ZpgwuBIE=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

marc nicole <mk1853387@gmail.com> wrote or quoted:
>I hope this question is not very far from the main topic of this list, but
>I have a hard time finding a way to check whether audio data samples are
>containing empty noise or actual significant voice/noise.

The Spectral Flatness Measure (SFM), also called Wiener entropy, can
separate the wheat from the chaff when it comes to how noise-like
a signal is. This measure runs the gamut from 0 to 1, where:
1 means you've hit pay dirt with perfect white noise (flat spectrum),
0 is as pure as a Napa Valley Chardonnay (single frequency).
(Everything in between is just different shades of gnarly.)

import numpy as np
from scipy.signal import welch

def noiseness(signal, fs):
# Compute the power spectral density
f, psd = welch(signal, fs, nperseg=min(len(signal), 256))

# Compute geometric mean of PSD
geometric_mean = np.exp(np.mean(np.log(psd + 1e-10)))

# Compute arithmetic mean of PSD
arithmetic_mean = np.mean(psd)

# Calculate Spectral Flatness Measure
sfm = geometric_mean / arithmetic_mean

return sfm

Subject: Re: How to check whether audio bytes contain empty noise or actual voice/signal?
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Fri, 25 Oct 2024 17:00 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: How to check whether audio bytes contain empty noise or actual voice/signal?
Date: 25 Oct 2024 17:00:14 GMT
Organization: Stefan Ram
Lines: 35
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <flatness-20241025175506@ram.dialup.fu-berlin.de>
References: <mailman.48.1729873488.4695.python-list@python.org> <noise-20241025174236@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 7iwgbiNtPB+1HkjcIXAbOQM7L3+zP6MzvkW72lfR4SDG1Z
Cancel-Lock: sha1:7W5Xju8SPYqEYEW+sZOmDacww1I= sha256:ZMhRquJuJcSBD0DA0lNrV4uUNyFr2XxDXHMcxxF/GY4=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>marc nicole <mk1853387@gmail.com> wrote or quoted:
>>I hope this question is not very far from the main topic of this list, but
>>I have a hard time finding a way to check whether audio data samples are
>>containing empty noise or actual significant voice/noise.
>The Spectral Flatness Measure (SFM), also called Wiener entropy, can
>separate the wheat from the chaff when it comes to how noise-like
>a signal is.

You can also peep the envelope flatness (the flatness of the
volume). If you've got some white noise that's not bringing much to
the table, that envelope should be flatter than a pancake at IHOP.

import librosa
import numpy as np

def measure_volume_flatness(audio_path, sr=None):
# Load the audio file
y, sr = librosa.load(audio_path, sr=sr)

# Calculate the root mean square (RMS) energy for each frame
frame_length = 2048
hop_length = 512
rms = librosa.feature.rms(y=y, frame_length=frame_length, hop_length=hop_length)[0]

# Calculate the dynamic range
db_range = librosa.amplitude_to_db(np.max(rms)) - librosa.amplitude_to_db(np.min(rms))

# Normalize the dynamic range to a 0-1 scale
# Assuming a maximum possible dynamic range of 120 dB
flatness = 1 - (db_range / 120)

return flatness

Subject: Re: How to check whether audio bytes contain empty noise or actual voice/signal?
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Sat, 26 Oct 2024 11:16 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: How to check whether audio bytes contain empty noise or actual voice/signal?
Date: 26 Oct 2024 11:16:13 GMT
Organization: Stefan Ram
Lines: 89
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <nn-20241026120839@ram.dialup.fu-berlin.de>
References: <mailman.48.1729873488.4695.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Qt4MCpznxGAr4JnAllVmJwScGy5qQLn2ygajXQILk/3Tmi
Cancel-Lock: sha1:95MzoRlWrMHuZfPlTfQaS6Amwzc= sha256:Dih+Zdw0b/JPMoowBIsTnYTCh+y/pEWndCxqfW5qG04=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

marc nicole <mk1853387@gmail.com> wrote or quoted:
>I have a hard time finding a way to check whether audio data samples are
>containing empty noise or actual significant voice/noise.

Or, you could have a human do a quick listen to some audio files to
gauge the "empty-noise ratio," then use that number as the filename
as a float, and finally train up a neural net on this. E.g.,

0.99.wav # very empty
0.992.wav # very empty file #2
0.993.wav # very empty file #3

0.00.wav # very not empty file
0.002.wav # very not empty file #2

One possible approach:

import os
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam
import librosa

## Data Preparation

# Function to extract audio features
def extract_features(file_path):
audio, sr = librosa.load(file_path)
mfccs = librosa.feature.mfcc(y=audio, sr=sr, n_mfcc=13)
return np.mean(mfccs.T, axis=0)

# Load data from directory
directory = 'd' # for example
X = []
y = []

for filename in os.listdir(directory):
if filename.endswith('.wav'):
file_path = os.path.join(directory, filename)
X.append(extract_features(file_path))
y.append(float(filename[:-4])) # Assuming filename is the p value

X = np.array(X)
y = np.array(y)

# Split data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Feature scaling
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

## Neural Network Model

model = Sequential([
Dense(64, activation='relu', input_shape=(13,)),
Dense(32, activation='relu'),
Dense(1)
])

model.compile(optimizer=Adam(learning_rate=0.001), loss='mean_squared_error')

## Training

model.fit(X_train_scaled, y_train, epochs=100, batch_size=32, validation_split=0.2, verbose=1)

## Evaluation

test_loss = model.evaluate(X_test_scaled, y_test, verbose=0)
print(f"Test Loss: {test_loss}")

## Prediction Function

def predict_p(audio_file):
features = extract_features(audio_file)
scaled_features = scaler.transform(features.reshape(1, -1))
prediction = model.predict(scaled_features)
return prediction[0][0]

# Example usage
new_audio_file = 'path/to/new/audio/file.wav'
predicted_p = predict_p(new_audio_file)
print(f"Predicted p value: {predicted_p}")

1

rocksolid light 0.9.8
clearnet tor