Skip to content

Commit

Permalink
sound effects api
Browse files Browse the repository at this point in the history
  • Loading branch information
jwmke committed Apr 13, 2024
1 parent 8d90086 commit cefc404
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/api/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
DynamixelMotor,
DYNAMIXEL_MX_12_ADDR_CONFIG,
)
from pygame import mixer
import asyncio
import cv2

app = FastAPI()
camera = cv2.VideoCapture(1, cv2.CAP_DSHOW)
templates = Jinja2Templates(directory="templates")
mixer.init()

origins = [
"http://localhost:3000",
Expand Down Expand Up @@ -62,3 +64,15 @@ async def command(request: Request):
ctrl.set_velocity(Position2D(x_val, y_val, 0))

return {"status": "success"}

@app.post("/sfx")
async def command(request: Request):
data = await request.json()

if data.get("sfx") == "bloop":
mixer.music.load("./bloop.mp3")
elif data.get("sfx") == "bong":
mixer.music.load("./bong.mp3")
mixer.music.play()

return {"status": "success"}
Binary file added src/api/v1/bloop.mp3
Binary file not shown.
Binary file added src/api/v1/bong.mp3
Binary file not shown.

0 comments on commit cefc404

Please sign in to comment.