nazemi
commited on
Upload usage_speechVSnoise.py
Browse files- usage_speechVSnoise.py +21 -0
usage_speechVSnoise.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
class SpeechNoiseClassifier:
|
| 6 |
+
def __init__(self, model_name="speechVSnoise"):
|
| 7 |
+
self.model_name = model_name
|
| 8 |
+
self.pipe = pipeline("audio-classification", model=self.model_name)
|
| 9 |
+
|
| 10 |
+
def classify(self, file_path):
|
| 11 |
+
if not os.path.exists(file_path):
|
| 12 |
+
raise FileNotFoundError(f"File not found: {file_path}")
|
| 13 |
+
|
| 14 |
+
result = self.pipe(file_path)[0]
|
| 15 |
+
return result["label"]
|
| 16 |
+
|
| 17 |
+
audio_file = sys.argv[1]
|
| 18 |
+
classifier = SpeechNoiseClassifier()
|
| 19 |
+
label = classifier.classify(audio_file)
|
| 20 |
+
print(f"{audio_file} → {label}")
|
| 21 |
+
|