forked from Milkad0/ParkinsonIA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
227 additions
and
227 deletions.
There are no files selected for viewing
File renamed without changes
174 changes: 87 additions & 87 deletions
174
ParkinsonFrontEnd/lib/RecognitionLib.py → lib/RecognitionLib.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,88 @@ | ||
import joblib | ||
import parselmouth | ||
from parselmouth.praat import call | ||
import pandas as pd | ||
import numpy as np | ||
import sklearn | ||
|
||
|
||
def loadModel(PATH): | ||
clf = joblib.load(PATH) | ||
return clf | ||
|
||
def measurePitch(voiceID, f0min, f0max, unit): | ||
sound = parselmouth.Sound(voiceID) # read the sound | ||
pitch = call(sound, "To Pitch", 0.0, f0min, f0max) | ||
pointProcess = call(sound, "To PointProcess (periodic, cc)", f0min, f0max)#create a praat pitch object | ||
localJitter = call(pointProcess, "Get jitter (local)", 0, 0, 0.0001, 0.02, 1.3) | ||
localabsoluteJitter = call(pointProcess, "Get jitter (local, absolute)", 0, 0, 0.0001, 0.02, 1.3) | ||
rapJitter = call(pointProcess, "Get jitter (rap)", 0, 0, 0.0001, 0.02, 1.3) | ||
ppq5Jitter = call(pointProcess, "Get jitter (ppq5)", 0, 0, 0.0001, 0.02, 1.3) | ||
localShimmer = call([sound, pointProcess], "Get shimmer (local)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
localdbShimmer = call([sound, pointProcess], "Get shimmer (local_dB)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
apq3Shimmer = call([sound, pointProcess], "Get shimmer (apq3)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
aqpq5Shimmer = call([sound, pointProcess], "Get shimmer (apq5)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
apq11Shimmer = call([sound, pointProcess], "Get shimmer (apq11)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
harmonicity05 = call(sound, "To Harmonicity (cc)", 0.01, 500, 0.1, 1.0) | ||
hnr05 = call(harmonicity05, "Get mean", 0, 0) | ||
harmonicity15 = call(sound, "To Harmonicity (cc)", 0.01, 1500, 0.1, 1.0) | ||
hnr15 = call(harmonicity15, "Get mean", 0, 0) | ||
harmonicity25 = call(sound, "To Harmonicity (cc)", 0.01, 2500, 0.1, 1.0) | ||
hnr25 = call(harmonicity25, "Get mean", 0, 0) | ||
harmonicity35 = call(sound, "To Harmonicity (cc)", 0.01, 3500, 0.1, 1.0) | ||
hnr35 = call(harmonicity35, "Get mean", 0, 0) | ||
harmonicity38 = call(sound, "To Harmonicity (cc)", 0.01, 3800, 0.1, 1.0) | ||
hnr38 = call(harmonicity38, "Get mean", 0, 0) | ||
return localJitter, localabsoluteJitter, rapJitter, ppq5Jitter, localShimmer, localdbShimmer, apq3Shimmer, aqpq5Shimmer, apq11Shimmer, hnr05, hnr15 ,hnr25 ,hnr35 ,hnr38 | ||
|
||
|
||
def predict(clf, wavPath): | ||
file_list = [] | ||
localJitter_list = [] | ||
localabsoluteJitter_list = [] | ||
rapJitter_list = [] | ||
ppq5Jitter_list = [] | ||
localShimmer_list = [] | ||
localdbShimmer_list = [] | ||
apq3Shimmer_list = [] | ||
aqpq5Shimmer_list = [] | ||
apq11Shimmer_list = [] | ||
hnr05_list = [] | ||
hnr15_list = [] | ||
hnr25_list = [] | ||
hnr35_list = [] | ||
hnr38_list = [] | ||
|
||
sound = parselmouth.Sound(wavPath) | ||
(localJitter, localabsoluteJitter, rapJitter, ppq5Jitter, localShimmer, localdbShimmer, apq3Shimmer, aqpq5Shimmer, | ||
apq11Shimmer, hnr05, hnr15, hnr25, hnr35, hnr38) = measurePitch(sound, 75, 1000, "Hertz") | ||
localJitter_list.append(localJitter) # make a mean F0 list | ||
localabsoluteJitter_list.append(localabsoluteJitter) # make a sd F0 list | ||
rapJitter_list.append(rapJitter) | ||
ppq5Jitter_list.append(ppq5Jitter) | ||
localShimmer_list.append(localShimmer) | ||
localdbShimmer_list.append(localdbShimmer) | ||
apq3Shimmer_list.append(apq3Shimmer) | ||
aqpq5Shimmer_list.append(aqpq5Shimmer) | ||
apq11Shimmer_list.append(apq11Shimmer) | ||
hnr05_list.append(hnr05) | ||
hnr15_list.append(hnr15) | ||
hnr25_list.append(hnr25) | ||
hnr35_list.append(hnr35) | ||
hnr38_list.append(hnr38) | ||
|
||
toPred = pd.DataFrame(np.column_stack( | ||
[localJitter_list, localabsoluteJitter_list, rapJitter_list, ppq5Jitter_list, localShimmer_list, | ||
localdbShimmer_list, apq3Shimmer_list, aqpq5Shimmer_list, apq11Shimmer_list, hnr05_list, hnr15_list, | ||
hnr25_list]), | ||
columns=["Jitter_rel", "Jitter_abs", "Jitter_RAP", "Jitter_PPQ", "Shim_loc", "Shim_dB", | ||
"Shim_APQ3", "Shim_APQ5", "Shi_APQ11", "hnr05", "hnr15", | ||
"hnr25"]) # add these lists to pandas in the right order | ||
|
||
resp = clf.predict(toPred) | ||
resp = str(resp) | ||
|
||
if resp == "[1.]": | ||
return True | ||
else: | ||
import joblib | ||
import parselmouth | ||
from parselmouth.praat import call | ||
import pandas as pd | ||
import numpy as np | ||
import sklearn | ||
|
||
|
||
def loadModel(PATH): | ||
clf = joblib.load(PATH) | ||
return clf | ||
|
||
def measurePitch(voiceID, f0min, f0max, unit): | ||
sound = parselmouth.Sound(voiceID) # read the sound | ||
pitch = call(sound, "To Pitch", 0.0, f0min, f0max) | ||
pointProcess = call(sound, "To PointProcess (periodic, cc)", f0min, f0max)#create a praat pitch object | ||
localJitter = call(pointProcess, "Get jitter (local)", 0, 0, 0.0001, 0.02, 1.3) | ||
localabsoluteJitter = call(pointProcess, "Get jitter (local, absolute)", 0, 0, 0.0001, 0.02, 1.3) | ||
rapJitter = call(pointProcess, "Get jitter (rap)", 0, 0, 0.0001, 0.02, 1.3) | ||
ppq5Jitter = call(pointProcess, "Get jitter (ppq5)", 0, 0, 0.0001, 0.02, 1.3) | ||
localShimmer = call([sound, pointProcess], "Get shimmer (local)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
localdbShimmer = call([sound, pointProcess], "Get shimmer (local_dB)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
apq3Shimmer = call([sound, pointProcess], "Get shimmer (apq3)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
aqpq5Shimmer = call([sound, pointProcess], "Get shimmer (apq5)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
apq11Shimmer = call([sound, pointProcess], "Get shimmer (apq11)", 0, 0, 0.0001, 0.02, 1.3, 1.6) | ||
harmonicity05 = call(sound, "To Harmonicity (cc)", 0.01, 500, 0.1, 1.0) | ||
hnr05 = call(harmonicity05, "Get mean", 0, 0) | ||
harmonicity15 = call(sound, "To Harmonicity (cc)", 0.01, 1500, 0.1, 1.0) | ||
hnr15 = call(harmonicity15, "Get mean", 0, 0) | ||
harmonicity25 = call(sound, "To Harmonicity (cc)", 0.01, 2500, 0.1, 1.0) | ||
hnr25 = call(harmonicity25, "Get mean", 0, 0) | ||
harmonicity35 = call(sound, "To Harmonicity (cc)", 0.01, 3500, 0.1, 1.0) | ||
hnr35 = call(harmonicity35, "Get mean", 0, 0) | ||
harmonicity38 = call(sound, "To Harmonicity (cc)", 0.01, 3800, 0.1, 1.0) | ||
hnr38 = call(harmonicity38, "Get mean", 0, 0) | ||
return localJitter, localabsoluteJitter, rapJitter, ppq5Jitter, localShimmer, localdbShimmer, apq3Shimmer, aqpq5Shimmer, apq11Shimmer, hnr05, hnr15 ,hnr25 ,hnr35 ,hnr38 | ||
|
||
|
||
def predict(clf, wavPath): | ||
file_list = [] | ||
localJitter_list = [] | ||
localabsoluteJitter_list = [] | ||
rapJitter_list = [] | ||
ppq5Jitter_list = [] | ||
localShimmer_list = [] | ||
localdbShimmer_list = [] | ||
apq3Shimmer_list = [] | ||
aqpq5Shimmer_list = [] | ||
apq11Shimmer_list = [] | ||
hnr05_list = [] | ||
hnr15_list = [] | ||
hnr25_list = [] | ||
hnr35_list = [] | ||
hnr38_list = [] | ||
|
||
sound = parselmouth.Sound(wavPath) | ||
(localJitter, localabsoluteJitter, rapJitter, ppq5Jitter, localShimmer, localdbShimmer, apq3Shimmer, aqpq5Shimmer, | ||
apq11Shimmer, hnr05, hnr15, hnr25, hnr35, hnr38) = measurePitch(sound, 75, 1000, "Hertz") | ||
localJitter_list.append(localJitter) # make a mean F0 list | ||
localabsoluteJitter_list.append(localabsoluteJitter) # make a sd F0 list | ||
rapJitter_list.append(rapJitter) | ||
ppq5Jitter_list.append(ppq5Jitter) | ||
localShimmer_list.append(localShimmer) | ||
localdbShimmer_list.append(localdbShimmer) | ||
apq3Shimmer_list.append(apq3Shimmer) | ||
aqpq5Shimmer_list.append(aqpq5Shimmer) | ||
apq11Shimmer_list.append(apq11Shimmer) | ||
hnr05_list.append(hnr05) | ||
hnr15_list.append(hnr15) | ||
hnr25_list.append(hnr25) | ||
hnr35_list.append(hnr35) | ||
hnr38_list.append(hnr38) | ||
|
||
toPred = pd.DataFrame(np.column_stack( | ||
[localJitter_list, localabsoluteJitter_list, rapJitter_list, ppq5Jitter_list, localShimmer_list, | ||
localdbShimmer_list, apq3Shimmer_list, aqpq5Shimmer_list, apq11Shimmer_list, hnr05_list, hnr15_list, | ||
hnr25_list]), | ||
columns=["Jitter_rel", "Jitter_abs", "Jitter_RAP", "Jitter_PPQ", "Shim_loc", "Shim_dB", | ||
"Shim_APQ3", "Shim_APQ5", "Shi_APQ11", "hnr05", "hnr15", | ||
"hnr25"]) # add these lists to pandas in the right order | ||
|
||
resp = clf.predict(toPred) | ||
resp = str(resp) | ||
|
||
if resp == "[1.]": | ||
return True | ||
else: | ||
return False |
Binary file renamed
BIN
+2.73 KB
...__pycache__/RecognitionLib.cpython-37.pyc → ...__pycache__/RecognitionLib.cpython-37.pyc
Binary file not shown.
File renamed without changes.
Oops, something went wrong.