sound.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import nope01 from "@opencode-ai/ui/audio/nope-01.aac"
  2. import nope02 from "@opencode-ai/ui/audio/nope-02.aac"
  3. import nope03 from "@opencode-ai/ui/audio/nope-03.aac"
  4. import nope04 from "@opencode-ai/ui/audio/nope-04.aac"
  5. import nope05 from "@opencode-ai/ui/audio/nope-05.aac"
  6. import staplebops01 from "@opencode-ai/ui/audio/staplebops-01.aac"
  7. import staplebops02 from "@opencode-ai/ui/audio/staplebops-02.aac"
  8. import staplebops03 from "@opencode-ai/ui/audio/staplebops-03.aac"
  9. import staplebops04 from "@opencode-ai/ui/audio/staplebops-04.aac"
  10. import staplebops05 from "@opencode-ai/ui/audio/staplebops-05.aac"
  11. import staplebops06 from "@opencode-ai/ui/audio/staplebops-06.aac"
  12. import staplebops07 from "@opencode-ai/ui/audio/staplebops-07.aac"
  13. export const SOUND_OPTIONS = [
  14. { id: "staplebops-01", label: "Boopy", src: staplebops01 },
  15. { id: "staplebops-02", label: "Beepy", src: staplebops02 },
  16. { id: "staplebops-03", label: "Staplebops 03", src: staplebops03 },
  17. { id: "staplebops-04", label: "Staplebops 04", src: staplebops04 },
  18. { id: "staplebops-05", label: "Staplebops 05", src: staplebops05 },
  19. { id: "staplebops-06", label: "Staplebops 06", src: staplebops06 },
  20. { id: "staplebops-07", label: "Staplebops 07", src: staplebops07 },
  21. { id: "nope-01", label: "Nope 01", src: nope01 },
  22. { id: "nope-02", label: "Nope 02", src: nope02 },
  23. { id: "nope-03", label: "Oopsie", src: nope03 },
  24. { id: "nope-04", label: "Nope 04", src: nope04 },
  25. { id: "nope-05", label: "Nope 05", src: nope05 },
  26. ] as const
  27. export type SoundOption = (typeof SOUND_OPTIONS)[number]
  28. export type SoundID = SoundOption["id"]
  29. const soundById = Object.fromEntries(SOUND_OPTIONS.map((s) => [s.id, s.src])) as Record<SoundID, string>
  30. export function soundSrc(id: string | undefined) {
  31. if (!id) return
  32. if (!(id in soundById)) return
  33. return soundById[id as SoundID]
  34. }
  35. export function playSound(src: string | undefined) {
  36. if (typeof Audio === "undefined") return
  37. if (!src) return
  38. void new Audio(src).play().catch(() => undefined)
  39. }