add auto init functionallity; add base url for client
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import requests
|
||||
|
||||
from typing import List
|
||||
from typing import List, Optional, Dict, Any
|
||||
from auracast import auracast_config
|
||||
|
||||
from auracast.utils.read_lc3_file import read_lc3_file
|
||||
|
||||
BASE_URL = "http://127.0.0.1:5000" # Adjust based on your actual API URL
|
||||
BASE_URL = "http://127.0.0.1:5000" # Default base URL
|
||||
|
||||
|
||||
# TODO: put this to a common location
|
||||
class AuracastConfigGroup(auracast_config.AuracastGlobalConfig):
|
||||
@@ -14,30 +15,46 @@ class AuracastConfigGroup(auracast_config.AuracastGlobalConfig):
|
||||
]
|
||||
|
||||
|
||||
def request_init(request_data : AuracastConfigGroup):
|
||||
response = requests.post(f"{BASE_URL}/init", json=request_data.model_dump())
|
||||
def request_init(request_data : AuracastConfigGroup, base_url: Optional[str] = None):
|
||||
url = base_url if base_url is not None else BASE_URL
|
||||
response = requests.post(f"{url}/init", json=request_data.model_dump())
|
||||
if response.status_code != 200:
|
||||
raise(f"Error: {response.status_code}, {response.text}")
|
||||
|
||||
|
||||
def send_audio(data_dict):
|
||||
response = requests.post(f"{BASE_URL}/stream_lc3", json=data_dict)
|
||||
raise Exception(f"Error: {response.status_code}, {response.text}")
|
||||
return response.json()
|
||||
|
||||
|
||||
def shutdown():
|
||||
response = requests.post(f"{BASE_URL}/shutdown")
|
||||
return response.json()
|
||||
|
||||
def stop_audio():
|
||||
response = requests.post(f"{BASE_URL}/stop_audio")
|
||||
def send_audio(data_dict: Dict[str, str], base_url: Optional[str] = None):
|
||||
url = base_url if base_url is not None else BASE_URL
|
||||
response = requests.post(f"{url}/stream_lc3", json=data_dict)
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Error: {response.status_code}, {response.text}")
|
||||
return response.json()
|
||||
|
||||
|
||||
def get_status():
|
||||
response = requests.get(f"{BASE_URL}/status")
|
||||
def shutdown(base_url: Optional[str] = None):
|
||||
url = base_url if base_url is not None else BASE_URL
|
||||
response = requests.post(f"{url}/shutdown")
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Error: {response.status_code}, {response.text}")
|
||||
return response.json()
|
||||
|
||||
|
||||
def stop_audio(base_url: Optional[str] = None):
|
||||
url = base_url if base_url is not None else BASE_URL
|
||||
response = requests.post(f"{url}/stop_audio")
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Error: {response.status_code}, {response.text}")
|
||||
return response.json()
|
||||
|
||||
|
||||
def get_status(base_url: Optional[str] = None):
|
||||
url = base_url if base_url is not None else BASE_URL
|
||||
response = requests.get(f"{url}/status")
|
||||
if response.status_code != 200:
|
||||
raise Exception(f"Error: {response.status_code}, {response.text}")
|
||||
return response.json()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
config = AuracastConfigGroup(
|
||||
auracast_config.AuracastBigConfigDeu()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from typing import List
|
||||
import glob
|
||||
import logging as log
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from auracast import multicast_control, auracast_config
|
||||
|
||||
app = FastAPI()
|
||||
@@ -19,6 +18,12 @@ async def initialize(conf: auracast_config.AuracastConfigGroup):
|
||||
global global_config_group
|
||||
global multicaster
|
||||
try:
|
||||
if conf.transport == 'auto':
|
||||
serial_devices = glob.glob('/dev/serial/by-id/*')
|
||||
for device in serial_devices:
|
||||
if 'usb-ZEPHYR_Zephyr_HCI_UART_sample' in device:
|
||||
conf.transport = f'serial:{device},115200,rtscts'
|
||||
break
|
||||
# initialize the streams dict
|
||||
global_config_group = conf
|
||||
log.info(
|
||||
@@ -75,10 +80,13 @@ async def stop_audio():
|
||||
async def get_status():
|
||||
"""Gets the current status of the multicaster."""
|
||||
if multicaster:
|
||||
status = multicaster.get_status()
|
||||
return {"status": status}
|
||||
return multicaster.get_status()
|
||||
else:
|
||||
return {"status": None}
|
||||
return {
|
||||
'is_initialized': False,
|
||||
'is_streaming': False,
|
||||
}
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user