Implement Call Recording for STT and Replay #3
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@
|
||||
*.log
|
||||
*.db
|
||||
*.conf
|
||||
configs/*
|
||||
configs/*
|
||||
*.json
|
||||
@@ -9,7 +9,6 @@ from internal.logger import create_logger
|
||||
from internal.op25_config_utls import scan_local_library
|
||||
import paho.mqtt.client as mqtt
|
||||
import requests
|
||||
from google.cloud import storage
|
||||
|
||||
# Initialize logging
|
||||
LOGGER = create_logger(__name__)
|
||||
@@ -23,7 +22,6 @@ NODE_ID = os.getenv("NODE_ID", "standalone-node")
|
||||
MQTT_BROKER = os.getenv("MQTT_BROKER", None)
|
||||
NODE_LAT = os.getenv("NODE_LAT")
|
||||
NODE_LONG = os.getenv("NODE_LONG")
|
||||
AUDIO_BUCKET = os.getenv("AUDIO_BUCKET")
|
||||
|
||||
# Global flag to track MQTT connection state
|
||||
MQTT_CONNECTED = False
|
||||
@@ -246,16 +244,16 @@ async def mqtt_lifecycle_manager():
|
||||
recorder_proc = None
|
||||
|
||||
def upload_audio(call_id):
|
||||
if not AUDIO_BUCKET: return None
|
||||
if not MQTT_BROKER: return None
|
||||
local_path = f"/calls/{call_id}.mp3"
|
||||
if not os.path.exists(local_path): return None
|
||||
|
||||
try:
|
||||
client = storage.Client()
|
||||
bucket = client.bucket(AUDIO_BUCKET)
|
||||
blob = bucket.blob(f"audio/{call_id}.mp3")
|
||||
blob.upload_from_filename(local_path, content_type="audio/mpeg")
|
||||
return f"gs://{AUDIO_BUCKET}/audio/{call_id}.mp3"
|
||||
with open(local_path, "rb") as f:
|
||||
files = {"file": (f"{call_id}.mp3", f, "audio/mpeg")}
|
||||
response = requests.post(f"{MQTT_BROKER}/upload", files=files, data={"node_id": NODE_ID, "call_id": call_id}, timeout=30)
|
||||
response.raise_for_status()
|
||||
return response.json().get("url")
|
||||
except Exception as e:
|
||||
LOGGER.error(f"Upload failed: {e}")
|
||||
return None
|
||||
|
||||
@@ -3,5 +3,4 @@ uvicorn[standard]
|
||||
paho-mqtt
|
||||
pydantic
|
||||
python-multipart
|
||||
requests
|
||||
google-cloud-storage
|
||||
requests
|
||||
Reference in New Issue
Block a user