46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import os
|
|
import subprocess
|
|
|
|
import httpx
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
API_KEY = os.environ["API_KEY"]
|
|
HOST = os.environ["HOST"]
|
|
BASE = f"https://{HOST}/proxy/protect/integration/v1"
|
|
HEADERS = {"X-API-Key": API_KEY}
|
|
CAMERA_NAME = "G6 Pro 360"
|
|
AUDIO_FILE = "./data/hello.wav"
|
|
VOLUME = 1.0 # 10%
|
|
|
|
|
|
def main():
|
|
with httpx.Client(headers=HEADERS, verify=False) as client:
|
|
cameras = client.get(f"{BASE}/cameras").raise_for_status().json()
|
|
camera = next(c for c in cameras if CAMERA_NAME in c["name"])
|
|
print(f"Camera: {camera['name']} ({camera['id']})")
|
|
|
|
session = client.post(f"{BASE}/cameras/{camera['id']}/talkback-session").raise_for_status().json()
|
|
print(f"Talkback: {session['url']} ({session['codec']} {session['samplingRate']}Hz)")
|
|
|
|
proc = subprocess.Popen([
|
|
"ffmpeg", "-re", "-i", AUDIO_FILE,
|
|
"-af", f"volume={VOLUME}",
|
|
"-acodec", "libopus",
|
|
"-ar", str(session["samplingRate"]),
|
|
"-ac", "1",
|
|
"-b:a", "64k",
|
|
"-f", "rtp", session["url"],
|
|
])
|
|
|
|
try:
|
|
proc.wait()
|
|
except KeyboardInterrupt:
|
|
proc.terminate()
|
|
proc.wait()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|