nsajadi commited on
Commit
693009c
1 Parent(s): 114374d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -6
app.py CHANGED
@@ -1,10 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
- import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- pipe = pipeline('sentiment-analysis')
5
- text = st.text_area('Enter some text here!')
 
 
 
 
 
 
 
6
 
7
- if text:
8
- out = pipe(text)
9
- st.json(out)
10
 
 
1
+ #from transformers import pipeline
2
+ #import streamlit as st
3
+
4
+ #pipe = pipeline('sentiment-analysis')
5
+ #text = st.text_area('Enter some text here!')
6
+
7
+ #if text:
8
+ # out = pipe(text)
9
+ # st.json(out)
10
+
11
+
12
  from transformers import pipeline
13
+ import torch
14
+
15
+ classifier = pipeline(
16
+ "audio-classification", model="MIT/ast-finetuned-speech-commands-v2", device=device
17
+ )
18
+
19
+ from transformers.pipelines.audio_utils import ffmpeg_microphone_live
20
+
21
+
22
+ def launch_fn(
23
+ wake_word="marvin",
24
+ prob_threshold=0.5,
25
+ chunk_length_s=2.0,
26
+ stream_chunk_s=1,
27
+ debug=False,
28
+ ):
29
+ if wake_word not in classifier.model.config.label2id.keys():
30
+ raise ValueError(
31
+ f"Wake word {wake_word} not in set of valid class labels, pick a wake word in the set {classifier.model.config.label2id.keys()}."
32
+ )
33
+
34
+ sampling_rate = classifier.feature_extractor.sampling_rate
35
+
36
+ mic = ffmpeg_microphone_live(
37
+ sampling_rate=sampling_rate,
38
+ chunk_length_s=chunk_length_s,
39
+ stream_chunk_s=stream_chunk_s,
40
+ )
41
 
42
+ print("Listening for wake word...")
43
+ mic_results = classifier(mic)
44
+ for prediction in mic_results:
45
+ prediction = prediction[0]
46
+ if debug:
47
+ print(prediction)
48
+ if prediction["label"] == wake_word:
49
+ if prediction["score"] > prob_threshold:
50
+ return True
51
 
52
+ launch_fn(debug=True)
 
 
53