Spaces:
Runtime error
Runtime error
Update AudioClassifier.py
Browse files- AudioClassifier.py +8 -2
AudioClassifier.py
CHANGED
@@ -18,6 +18,7 @@ class AudioClassifier:
|
|
18 |
|
19 |
Attributes:
|
20 |
vocab (list): Vocabulary of valid commands
|
|
|
21 |
pipe: The Hugging Face Transformers pipeline for audio classification.
|
22 |
"""
|
23 |
|
@@ -28,6 +29,9 @@ class AudioClassifier:
|
|
28 |
self.vocab = ["left", "right", "up", "down", "go", "follow",
|
29 |
"on", "off", "one", "two", "three", "stop"]
|
30 |
|
|
|
|
|
|
|
31 |
# Load the audio classification pipeline
|
32 |
self.pipe = pipeline("audio-classification", model="0xb1/wav2vec2-base-finetuned-speech_commands-v0.02")
|
33 |
|
@@ -44,9 +48,11 @@ class AudioClassifier:
|
|
44 |
_, audio = wavfile.read(audio_path)
|
45 |
audio = decimate(audio, 3)
|
46 |
result = self.pipe(audio)[0]["label"]
|
47 |
-
|
48 |
if result not in self.vocab:
|
49 |
-
result = 'unknown'
|
|
|
|
|
50 |
|
51 |
return result
|
52 |
|
|
|
18 |
|
19 |
Attributes:
|
20 |
vocab (list): Vocabulary of valid commands
|
21 |
+
commands (list): List of corresponding mouse actions
|
22 |
pipe: The Hugging Face Transformers pipeline for audio classification.
|
23 |
"""
|
24 |
|
|
|
29 |
self.vocab = ["left", "right", "up", "down", "go", "follow",
|
30 |
"on", "off", "one", "two", "three", "stop"]
|
31 |
|
32 |
+
self.commands = ["left click", "right click", "scroll up", "scroll down", "double click", "sustained click", "enable cursor movement",
|
33 |
+
"disable cursor movement", "slow cursor speed", "medium cursor speed", "fast cursor speed", "finish the application"]
|
34 |
+
|
35 |
# Load the audio classification pipeline
|
36 |
self.pipe = pipeline("audio-classification", model="0xb1/wav2vec2-base-finetuned-speech_commands-v0.02")
|
37 |
|
|
|
48 |
_, audio = wavfile.read(audio_path)
|
49 |
audio = decimate(audio, 3)
|
50 |
result = self.pipe(audio)[0]["label"]
|
51 |
+
|
52 |
if result not in self.vocab:
|
53 |
+
result = 'unknown command'
|
54 |
+
else:
|
55 |
+
result = result + ' ---> ' + '(' + self.commands[self.vocab.index(result)] + ')'
|
56 |
|
57 |
return result
|
58 |
|