Exemple #1
0
def Manage(file_name):  #c => count, c_a = count_apnea
    count = 0
    count_apnea = 0
    #file = 'out_tests.wav'
    file = file_name
    #print(file)
    #result = WAV.DeTect(n,str)
    temp = WAV.DeTect(2, file)
    result = [0, 0, 0, 0]
    result[0] = temp[0]  # 무호흡 환자 진단 카운트
    result[1] = temp[3]  # 무호흡 횟수 카운트
    result[2] = temp[1]  #가장 큰 소음 dB
    result[3] = temp[2]  #평균 소음 dB
    return result
Exemple #2
0
import matplotlib.pyplot as plot
import WAV as wav
import STFT as stft
from Oscillator import *

# Load sample input...
# x, sr = wav.read("wav/tomsawyer.wav")

# or produce cos wave
# sr = 44100.0
# osc = Oscillator(sr, 440.0)
# x = 0.5 * osc.getBuffer(123456)

# Set STFT parameters
winSize = 1024 * 2  # in samples
hopSize = winSize / 4  # in samples

# Build output signal
frames = stft.stft(x, winSize, hopSize)
y = stft.istft(frames, winSize, hopSize)

# Plot x-y difference
n = min(len(x), len(y))
diff = abs(x[0:n] - y[0:n])
plot.figure()
plot.plot(diff, "b")
plot.show()

# Write out results
wav.write(x, sr, "wav/stft_input.wav")
wav.write(y, sr, "wav/stft_output.wav")
Exemple #3
0
from numpy import *
import matplotlib.pyplot as plot
import WAV as wav
from VAD import vad
import scipy

# Load sample input
x, sr = wav.read("wav/test/test_bh_raw.wav")

# Set VAD parameters
winSize = int(sr * 20e-3)  # in samples (fs*s)
hopSize = winSize  # in samples
smoothingGain = [0.3, 0.02
                 ]  # small numbers TODO: calculte for 0-values 0.1, 0.2, 0.3
triggerThresholds = [-25, -20]  # in dBFS

# Estimate silent frames
vadFlags = vad(x, winSize, hopSize, smoothingGain, triggerThresholds)

# Plot results
plot.figure()
plot.plot(x, "b")
#plot.plot(range(0, len(x)-winSize, hopSize), vadFlags*max(x), "r")
plot.plot(range(0,
                len(x) - winSize, hopSize),
          vadFlags[:, 1],
          "r",
          linewidth=2)  # TEST
plot.plot(range(0, len(x) - winSize, hopSize), vadFlags[:, 2], "b")
plot.plot(range(len(x)), triggerThresholds[0] * ones(len(x)), "g--")
plot.plot(range(len(x)), triggerThresholds[1] * ones(len(x)), "g--")
Exemple #4
0
from numpy import *
import matplotlib.pyplot as plot
import WAV as wav
from VAD import vad
import scipy

# Load sample input
x, sr = wav.read("wav/test/test_bh_raw.wav")

# Set VAD parameters
winSize = int(sr*20e-3)         # in samples (fs*s)
hopSize = winSize               # in samples
smoothingGain = [0.3, 0.02]     # small numbers TODO: calculte for 0-values 0.1, 0.2, 0.3
triggerThresholds = [-25, -20]  # in dBFS

# Estimate silent frames
vadFlags = vad(x, winSize, hopSize, smoothingGain, triggerThresholds)

# Plot results
plot.figure()
plot.plot(x, "b")
#plot.plot(range(0, len(x)-winSize, hopSize), vadFlags*max(x), "r")
plot.plot(range(0, len(x)-winSize, hopSize), vadFlags[:,1], "r", linewidth=2) # TEST
plot.plot(range(0, len(x)-winSize, hopSize), vadFlags[:,2], "b")
plot.plot(range(len(x)), triggerThresholds[0]*ones(len(x)), "g--")
plot.plot(range(len(x)), triggerThresholds[1]*ones(len(x)), "g--")
plot.show()
Exemple #5
0
import matplotlib.pyplot as plot
import WAV as wav
import STFT as stft
from Oscillator import *

# Load sample input...
# x, sr = wav.read("wav/tomsawyer.wav")

# or produce cos wave
# sr = 44100.0
# osc = Oscillator(sr, 440.0)
# x = 0.5 * osc.getBuffer(123456)

# Set STFT parameters
winSize = 1024*2      # in samples
hopSize = winSize/4   # in samples

# Build output signal
frames = stft.stft(x, winSize, hopSize)
y = stft.istft(frames, winSize, hopSize)

# Plot x-y difference
n = min(len(x), len(y))
diff = abs(x[0:n] - y[0:n])
plot.figure()
plot.plot(diff, "b")
plot.show()

# Write out results
wav.write(x, sr, "wav/stft_input.wav")
wav.write(y, sr, "wav/stft_output.wav")
Exemple #6
0
from numpy import *
import matplotlib.pyplot as plot
import WAV as wav
from VAD import vad, mute

filename = "tomsawyer.wav"

# Load sample input
x, sr = wav.read("wav/" + filename)

# Set VAD parameters
winSize = int(sr*20e-3)         # in samples (fs*s)
hopSize = winSize               # in samples
smoothingGain = [0.3, 0.02]     # small numbers
triggerThresholds = [-25, -20]  # in dBFS

# Estimate silent frames
vadFlags = vad(x, winSize, hopSize, smoothingGain, triggerThresholds)

# Mute silent frames
y = mute(x, winSize, hopSize, vadFlags)

# Plot results
plot.figure()
plot.plot(x, "b")
plot.plot(y, "r")
plot.plot(range(0, len(y)-winSize, hopSize), vadFlags[:,1], "g--")
plot.legend(("Input signal", "Output signal", "Signal offset"))
plot.show()

# Write out results
Exemple #7
0
from numpy import *
from Oscillator import *
#import matplotlib.pyplot as plot

import WAV as wav

[input, sr] = wav.read('wav/x1.wav')

oscillator = Oscillator(sr, 1000.0)

wave = oscillator.getBuffer(len(input))

output = multiply(input, wave)

#wav.sound(input, sr, "/tmp/input.wav")
wav.sound(output, sr, "/tmp/output.wav")
Exemple #8
0
from numpy import *
import WAV as wav
from Oscillator import *

# Load sample input
[x, sr] = wav.read('wav/tomsawyer.wav')

# Make cos wave
osc = Oscillator(sr, 500.0)
f = osc.getBuffer(len(x))

# Shift frequency by f Hz
y = multiply(x, f)

# Write out results
wav.write(x, sr, "wav/freqshift_input.wav")
wav.write(y, sr, "wav/freqshift_output.wav")
Exemple #9
0
from numpy import *
import matplotlib.pyplot as plot
import WAV as wav
from VAD import vad, mute

filename = "tomsawyer.wav"

# Load sample input
x, sr = wav.read("wav/" + filename)

# Set VAD parameters
winSize = int(sr * 20e-3)  # in samples (fs*s)
hopSize = winSize  # in samples
smoothingGain = [0.3, 0.001]  # small numbers
triggerThresholds = [-25, -20]  # in dBFS

# Estimate silent frames
vadFlags = vad(x, winSize, hopSize, smoothingGain, triggerThresholds)

# Mute silent frames
y = mute(x, winSize, hopSize, vadFlags)

# Plot results
plot.figure()
plot.plot(x, "b")
plot.plot(y, "r")
plot.plot(range(0, len(y) - winSize + 1, hopSize), vadFlags[:, 1], "g--")
plot.legend(("Input signal", "Output signal", "Signal offset"))
plot.show()

# Write out results
Exemple #10
0
from numpy import *
import matplotlib.pyplot as plot
import WAV as wav

def rotate(array, n=1):
    n = n % len(array)
    return array[n:] + array[:n]

def rms(array):
    result = 0
    for i in range(len(array)):
        result += array[i] * array[i]
    return result # sqrt(result/len(array))

# Input data
x = wav.read("samples/test.wav")
x = x[0]

# Output data
y = zeros(len(x))

# Init RMS buffer
rmsBufferSize = 10;
rmsBuffer = zeros(rmsBufferSize);

# Fill output data
for i in range(len(x)):
    rmsBuffer[0] = x[i]
    y[i] = rms(rmsBuffer)
    bla = rotate(rmsBuffer)