Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,20 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
import numpy as np
|
| 4 |
-
import sounddevice as sd
|
| 5 |
-
import queue
|
| 6 |
-
import time
|
| 7 |
-
import requests # To trigger Flask endpoint
|
| 8 |
|
| 9 |
-
|
| 10 |
-
FLASK_URL = "http://127.0.0.1:5000/trigger_wake_word"
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
waveform_queue = queue.Queue()
|
| 15 |
|
| 16 |
-
|
| 17 |
-
def
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
waveform_queue.put(indata.copy())
|
| 21 |
|
| 22 |
-
|
| 23 |
-
def
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
waveform = torch.tensor(waveform).mean(dim=1) # Convert stereo to mono
|
| 27 |
-
waveform = waveform.unsqueeze(0) # Add batch dimension
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
transcript = model(waveform)[0]
|
| 32 |
-
|
| 33 |
-
transcript = transcript.lower()
|
| 34 |
-
print(f"Detected: {transcript}")
|
| 35 |
-
|
| 36 |
-
if "hi biriyani hub" in transcript:
|
| 37 |
-
print("Wake word detected!")
|
| 38 |
-
requests.get(FLASK_URL) # Trigger Flask route
|
| 39 |
-
break
|
| 40 |
-
|
| 41 |
-
# Start capturing audio in a background thread
|
| 42 |
-
def start_listening():
|
| 43 |
-
with sd.InputStream(callback=callback, channels=1, samplerate=16000):
|
| 44 |
-
detect_wake_word()
|
| 45 |
-
|
| 46 |
-
# Run Wake Word Detection
|
| 47 |
-
if __name__ == "__main__":
|
| 48 |
-
start_listening()
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from flask import Flask, render_template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
app = Flask(__name__)
|
|
|
|
| 5 |
|
| 6 |
+
# Get Hugging Face assigned port, default to 7860 if running locally
|
| 7 |
+
PORT = int(os.getenv("PORT", 7860))
|
|
|
|
| 8 |
|
| 9 |
+
@app.route('/')
|
| 10 |
+
def index():
|
| 11 |
+
"""Serve the main page with voice recognition."""
|
| 12 |
+
return render_template('index.html')
|
|
|
|
| 13 |
|
| 14 |
+
@app.route('/landing')
|
| 15 |
+
def landing():
|
| 16 |
+
"""Landing page that loads after wake-word detection."""
|
| 17 |
+
return render_template('landing.html')
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
if __name__ == '__main__':
|
| 20 |
+
app.run(host="0.0.0.0", port=PORT, debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|