Spaces:
Runtime error
Runtime error
finished setup
Browse files- __pycache__/run_command_responses.cpython-38.pyc +0 -0
- app.py +40 -4
- assets/command_responses/cooled_activated.wav +0 -0
- assets/command_responses/cooled_deactivated.wav +0 -0
- assets/command_responses/heated_activated.wav +0 -0
- assets/command_responses/heated_deactivated.wav +0 -0
- assets/command_responses/massage_activated.wav +0 -0
- assets/command_responses/massage_deactivated.wav +0 -0
- command_responses/cooled_seats_activated.m4a +0 -0
- command_responses/cooled_seats_deactivated.m4a +0 -0
- command_responses/heated_seats_activated.m4a +0 -0
- command_responses/heated_seats_deactivated.m4a +0 -0
- command_responses/massage_seats_activated.m4a +0 -0
- command_responses/massage_seats_deactivated.m4a +0 -0
- requirements.txt +2 -1
- run_command_responses.py +21 -0
- script.py +12 -0
__pycache__/run_command_responses.cpython-38.pyc
ADDED
Binary file (1.64 kB). View file
|
|
app.py
CHANGED
@@ -5,6 +5,26 @@ import librosa
|
|
5 |
import torch
|
6 |
from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
|
7 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
load_dotenv()
|
10 |
|
@@ -13,12 +33,23 @@ os.environ["PATH"] += ".\env\Lib\site-packages\ffprobe"
|
|
13 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
14 |
MODEL = os.getenv("MODEL")
|
15 |
|
|
|
|
|
16 |
model = Speech2TextForConditionalGeneration.from_pretrained(
|
17 |
"facebook/s2t-small-librispeech-asr"
|
18 |
)
|
19 |
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-librispeech-asr")
|
20 |
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def transcribe(audio):
|
23 |
input, rate = librosa.load(
|
24 |
audio, sr=16000
|
@@ -28,9 +59,14 @@ def transcribe(audio):
|
|
28 |
inputs["input_features"], attention_mask=inputs["attention_mask"]
|
29 |
)
|
30 |
transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
31 |
-
|
|
|
|
|
32 |
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
5 |
import torch
|
6 |
from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
|
7 |
from dotenv import load_dotenv
|
8 |
+
import openai
|
9 |
+
from run_command_responses import ResponseManager as rs
|
10 |
+
|
11 |
+
resoponses = {
|
12 |
+
"heated_seats_on": rs.activate_heated_seats,
|
13 |
+
"heated_seats_off": rs.deactivate_heated_seats,
|
14 |
+
"cooled_seats_on": rs.activate_cooled_seats,
|
15 |
+
"cooled_seats_off": rs.deactivate_cooled_seats,
|
16 |
+
"massage_seats_on": rs.activate_massage_seats,
|
17 |
+
"massage_seats_off": rs.deactivate_massage_seats,
|
18 |
+
}
|
19 |
+
|
20 |
+
id2label = {
|
21 |
+
1: "massage_seats_on",
|
22 |
+
2: "massage_seats_off",
|
23 |
+
3: "heated_seats_on",
|
24 |
+
4: "heated_seats_off",
|
25 |
+
5: "cooled_seats_on",
|
26 |
+
6: "cooled_seats_off",
|
27 |
+
}
|
28 |
|
29 |
load_dotenv()
|
30 |
|
|
|
33 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
34 |
MODEL = os.getenv("MODEL")
|
35 |
|
36 |
+
openai.api_key = OPENAI_API_KEY
|
37 |
+
|
38 |
model = Speech2TextForConditionalGeneration.from_pretrained(
|
39 |
"facebook/s2t-small-librispeech-asr"
|
40 |
)
|
41 |
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-librispeech-asr")
|
42 |
|
43 |
|
44 |
+
def get_command(command, model, id2label):
|
45 |
+
completion = openai.Completion.create(
|
46 |
+
model=model, prompt=f"{command}->", max_tokens=1, temperature=0
|
47 |
+
)
|
48 |
+
id = int(completion["choices"][0]["text"].strip())
|
49 |
+
result = id2label[id] if id in id2label else "unknown"
|
50 |
+
return result
|
51 |
+
|
52 |
+
|
53 |
def transcribe(audio):
|
54 |
input, rate = librosa.load(
|
55 |
audio, sr=16000
|
|
|
59 |
inputs["input_features"], attention_mask=inputs["attention_mask"]
|
60 |
)
|
61 |
transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
62 |
+
result = get_command(transcription, MODEL, id2label)
|
63 |
+
resoponses.get(result)()
|
64 |
+
return result
|
65 |
|
66 |
|
67 |
+
if __name__ == "__main__":
|
68 |
+
gr.Interface(
|
69 |
+
fn=transcribe,
|
70 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
71 |
+
outputs="text",
|
72 |
+
).launch()
|
assets/command_responses/cooled_activated.wav
ADDED
Binary file (389 kB). View file
|
|
assets/command_responses/cooled_deactivated.wav
ADDED
Binary file (451 kB). View file
|
|
assets/command_responses/heated_activated.wav
ADDED
Binary file (578 kB). View file
|
|
assets/command_responses/heated_deactivated.wav
ADDED
Binary file (451 kB). View file
|
|
assets/command_responses/massage_activated.wav
ADDED
Binary file (557 kB). View file
|
|
assets/command_responses/massage_deactivated.wav
ADDED
Binary file (549 kB). View file
|
|
command_responses/cooled_seats_activated.m4a
ADDED
Binary file (50.6 kB). View file
|
|
command_responses/cooled_seats_deactivated.m4a
ADDED
Binary file (58.3 kB). View file
|
|
command_responses/heated_seats_activated.m4a
ADDED
Binary file (73.1 kB). View file
|
|
command_responses/heated_seats_deactivated.m4a
ADDED
Binary file (58.6 kB). View file
|
|
command_responses/massage_seats_activated.m4a
ADDED
Binary file (71.1 kB). View file
|
|
command_responses/massage_seats_deactivated.m4a
ADDED
Binary file (70.3 kB). View file
|
|
requirements.txt
CHANGED
@@ -7,4 +7,5 @@ sounddevice
|
|
7 |
librosa
|
8 |
python-dotenv
|
9 |
ffmpeg
|
10 |
-
ffprobe
|
|
|
|
7 |
librosa
|
8 |
python-dotenv
|
9 |
ffmpeg
|
10 |
+
ffprobe
|
11 |
+
playsound==1.2.2
|
run_command_responses.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from playsound import playsound
|
2 |
+
|
3 |
+
|
4 |
+
class ResponseManager:
|
5 |
+
def activate_heated_seats():
|
6 |
+
playsound("assets\command_responses\heated_activated.wav")
|
7 |
+
|
8 |
+
def deactivate_heated_seats():
|
9 |
+
playsound("assets\command_responses\heated_deactivated.wav")
|
10 |
+
|
11 |
+
def activate_cooled_seats():
|
12 |
+
playsound("assets\command_responses\cooled_activated.wav")
|
13 |
+
|
14 |
+
def deactivate_cooled_seats():
|
15 |
+
playsound("assets\command_responses\cooled_deactivated.wav")
|
16 |
+
|
17 |
+
def activate_massage_seats():
|
18 |
+
playsound("assets\command_responses\massage_activated.wav")
|
19 |
+
|
20 |
+
def deactivate_massage_seats():
|
21 |
+
playsound("assets\command_responses\massage_deactivated.wav")
|
script.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pydub import AudioSegment
|
3 |
+
|
4 |
+
path = "command_responses"
|
5 |
+
file_names = os.listdir(path)
|
6 |
+
res_path = "assets\command_responses"
|
7 |
+
|
8 |
+
for file_name in file_names:
|
9 |
+
m4a_file = file_name
|
10 |
+
wav_filename = os.path.splitext(file_name)[0] + ".wav"
|
11 |
+
track = AudioSegment.from_file(os.path.join(path, m4a_file), format="m4a")
|
12 |
+
file_handle = track.export(os.path.join(res_path, wav_filename), format="wav")
|