Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from gtts import gTTS # type: ignore
|
|
6 |
from pydub import AudioSegment
|
7 |
from pydub.playback import play
|
8 |
|
9 |
-
# Dog sound files (Ensure these files exist)
|
10 |
dog_sounds = {
|
11 |
"sit": "dog_sit.mp3",
|
12 |
"come": "dog_come.mp3",
|
@@ -40,11 +40,16 @@ def dog_response(command):
|
|
40 |
if command:
|
41 |
for key in dog_sounds:
|
42 |
if key in command:
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
def play_dog_sound(sound_file):
|
50 |
"""Plays an audio file using Pygame."""
|
@@ -64,25 +69,21 @@ def generate_speech(text):
|
|
64 |
return speech_file # Return audio file for Gradio
|
65 |
|
66 |
def process_command(audio_file):
|
|
|
67 |
command = recognize_speech(audio_file)
|
68 |
-
|
69 |
-
|
|
|
|
|
70 |
|
71 |
# Gradio UI
|
72 |
iface = gr.Interface(
|
73 |
fn=process_command,
|
74 |
inputs=gr.Audio(sources=["microphone"], type="filepath"),
|
75 |
-
outputs=["
|
76 |
title="πΆ Dog Command Recognition πΆ",
|
77 |
description="π€ Speak a command and let the dog respond! π\n\nTry commands like 'sit', 'come', 'fetch', 'treat', 'play'",
|
78 |
-
theme="default",
|
79 |
live=True,
|
80 |
-
css="""
|
81 |
-
body { background-color: #f8f9fa; text-align: center; }
|
82 |
-
.output-text { color: #ff4500; font-size: 20px; font-weight: bold; }
|
83 |
-
.interface-title { color: #008080; font-size: 26px; font-weight: bold; }
|
84 |
-
.interface-description { color: #2f4f4f; font-size: 18px; }
|
85 |
-
"""
|
86 |
)
|
87 |
|
88 |
if __name__ == "__main__":
|
|
|
6 |
from pydub import AudioSegment
|
7 |
from pydub.playback import play
|
8 |
|
9 |
+
# Dog sound files (Ensure these files exist in the same directory)
|
10 |
dog_sounds = {
|
11 |
"sit": "dog_sit.mp3",
|
12 |
"come": "dog_come.mp3",
|
|
|
40 |
if command:
|
41 |
for key in dog_sounds:
|
42 |
if key in command:
|
43 |
+
sound_file = dog_sounds[key]
|
44 |
+
play_dog_sound(sound_file)
|
45 |
+
return sound_file, f"Playing sound for {key}", generate_speech(f"Woof! I heard you say {key}")
|
46 |
+
|
47 |
+
# If no specific command is recognized, play bark
|
48 |
+
sound_file = dog_sounds["bark"]
|
49 |
+
play_dog_sound(sound_file)
|
50 |
+
return sound_file, "No specific dog command recognized. Playing default bark sound.", generate_speech("Woof! I didn't recognize that, so I'll just bark!")
|
51 |
+
|
52 |
+
return None, "No command to process.", None
|
53 |
|
54 |
def play_dog_sound(sound_file):
|
55 |
"""Plays an audio file using Pygame."""
|
|
|
69 |
return speech_file # Return audio file for Gradio
|
70 |
|
71 |
def process_command(audio_file):
|
72 |
+
"""Processes the command from the user."""
|
73 |
command = recognize_speech(audio_file)
|
74 |
+
sound_file, response_text, speech_file = dog_response(command)
|
75 |
+
|
76 |
+
# Return the dog sound file in the first output
|
77 |
+
return sound_file, response_text, speech_file
|
78 |
|
79 |
# Gradio UI
|
80 |
iface = gr.Interface(
|
81 |
fn=process_command,
|
82 |
inputs=gr.Audio(sources=["microphone"], type="filepath"),
|
83 |
+
outputs=["audio", "text", "audio"], # First box now plays dog sound
|
84 |
title="πΆ Dog Command Recognition πΆ",
|
85 |
description="π€ Speak a command and let the dog respond! π\n\nTry commands like 'sit', 'come', 'fetch', 'treat', 'play'",
|
|
|
86 |
live=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
)
|
88 |
|
89 |
if __name__ == "__main__":
|