Skip to content

Commit

Permalink
Lazy load audio files in other yap implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Jan 12, 2025
1 parent d2e2b4c commit 7be8bd3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 62 deletions.
68 changes: 37 additions & 31 deletions lib/yap.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
import { Howl } from 'howler'
let yapping = false
const yap_sounds = {
// these sounds and most of the yapping code are adapted from https://github.com/equalo-official/animalese-generator
a: new Howl({ src: 'audio/yapping/a.wav' }),
b: new Howl({ src: 'audio/yapping/b.wav' }),
c: new Howl({ src: 'audio/yapping/c.wav' }),
d: new Howl({ src: 'audio/yapping/d.wav' }),
e: new Howl({ src: 'audio/yapping/e.wav' }),
f: new Howl({ src: 'audio/yapping/f.wav' }),
g: new Howl({ src: 'audio/yapping/g.wav' }),
h: new Howl({ src: 'audio/yapping/h.wav' }),
i: new Howl({ src: 'audio/yapping/i.wav' }),
j: new Howl({ src: 'audio/yapping/j.wav' }),
k: new Howl({ src: 'audio/yapping/k.wav' }),
l: new Howl({ src: 'audio/yapping/l.wav' }),
m: new Howl({ src: 'audio/yapping/m.wav' }),
n: new Howl({ src: 'audio/yapping/n.wav' }),
o: new Howl({ src: 'audio/yapping/o.wav' }),
p: new Howl({ src: 'audio/yapping/p.wav' }),
q: new Howl({ src: 'audio/yapping/q.wav' }),
r: new Howl({ src: 'audio/yapping/r.wav' }),
s: new Howl({ src: 'audio/yapping/s.wav' }),
t: new Howl({ src: 'audio/yapping/t.wav' }),
u: new Howl({ src: 'audio/yapping/u.wav' }),
v: new Howl({ src: 'audio/yapping/v.wav' }),
w: new Howl({ src: 'audio/yapping/w.wav' }),
x: new Howl({ src: 'audio/yapping/x.wav' }),
y: new Howl({ src: 'audio/yapping/y.wav' }),
z: new Howl({ src: 'audio/yapping/z.wav' }),
th: new Howl({ src: 'audio/yapping/th.wav' }),
sh: new Howl({ src: 'audio/yapping/sh.wav' }),
_: new Howl({ src: 'audio/yapping/_.wav' }),
let yap_sounds = {}
function loadYapSounds() {
yap_sounds = {
// these sounds and most of the yapping code are adapted from https://github.com/equalo-official/animalese-generator
a: new Howl({ src: 'audio/yapping/a.wav' }),
b: new Howl({ src: 'audio/yapping/b.wav' }),
c: new Howl({ src: 'audio/yapping/c.wav' }),
d: new Howl({ src: 'audio/yapping/d.wav' }),
e: new Howl({ src: 'audio/yapping/e.wav' }),
f: new Howl({ src: 'audio/yapping/f.wav' }),
g: new Howl({ src: 'audio/yapping/g.wav' }),
h: new Howl({ src: 'audio/yapping/h.wav' }),
i: new Howl({ src: 'audio/yapping/i.wav' }),
j: new Howl({ src: 'audio/yapping/j.wav' }),
k: new Howl({ src: 'audio/yapping/k.wav' }),
l: new Howl({ src: 'audio/yapping/l.wav' }),
m: new Howl({ src: 'audio/yapping/m.wav' }),
n: new Howl({ src: 'audio/yapping/n.wav' }),
o: new Howl({ src: 'audio/yapping/o.wav' }),
p: new Howl({ src: 'audio/yapping/p.wav' }),
q: new Howl({ src: 'audio/yapping/q.wav' }),
r: new Howl({ src: 'audio/yapping/r.wav' }),
s: new Howl({ src: 'audio/yapping/s.wav' }),
t: new Howl({ src: 'audio/yapping/t.wav' }),
u: new Howl({ src: 'audio/yapping/u.wav' }),
v: new Howl({ src: 'audio/yapping/v.wav' }),
w: new Howl({ src: 'audio/yapping/w.wav' }),
x: new Howl({ src: 'audio/yapping/x.wav' }),
y: new Howl({ src: 'audio/yapping/y.wav' }),
z: new Howl({ src: 'audio/yapping/z.wav' }),
th: new Howl({ src: 'audio/yapping/th.wav' }),
sh: new Howl({ src: 'audio/yapping/sh.wav' }),
_: new Howl({ src: 'audio/yapping/_.wav' }),
}
}

export async function yap(
Expand All @@ -43,6 +46,9 @@ export async function yap(
} = {},
) {
yapping = true
if (Object.keys(yap_sounds).length === 0) {
loadYapSounds()
}

return new Promise((resolve, reject) => {
const yap_queue = []
Expand Down
67 changes: 36 additions & 31 deletions src/app/harbor/shipyard/idea-generator/impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,39 @@ import Modal from '@/components/ui/modal'
import { Button } from '@/components/ui/button'
import { useChat } from 'ai/react'


const yap_sounds = {
a: new Howl({ src: 'audio/yapping/a.wav' }),
b: new Howl({ src: 'audio/yapping/b.wav' }),
c: new Howl({ src: 'audio/yapping/c.wav' }),
d: new Howl({ src: 'audio/yapping/d.wav' }),
e: new Howl({ src: 'audio/yapping/e.wav' }),
f: new Howl({ src: 'audio/yapping/f.wav' }),
g: new Howl({ src: 'audio/yapping/g.wav' }),
h: new Howl({ src: 'audio/yapping/h.wav' }),
i: new Howl({ src: 'audio/yapping/i.wav' }),
j: new Howl({ src: 'audio/yapping/j.wav' }),
k: new Howl({ src: 'audio/yapping/k.wav' }),
l: new Howl({ src: 'audio/yapping/l.wav' }),
m: new Howl({ src: 'audio/yapping/m.wav' }),
n: new Howl({ src: 'audio/yapping/n.wav' }),
o: new Howl({ src: 'audio/yapping/o.wav' }),
p: new Howl({ src: 'audio/yapping/p.wav' }),
q: new Howl({ src: 'audio/yapping/q.wav' }),
r: new Howl({ src: 'audio/yapping/r.wav' }),
s: new Howl({ src: 'audio/yapping/s.wav' }),
t: new Howl({ src: 'audio/yapping/t.wav' }),
u: new Howl({ src: 'audio/yapping/u.wav' }),
v: new Howl({ src: 'audio/yapping/v.wav' }),
w: new Howl({ src: 'audio/yapping/w.wav' }),
x: new Howl({ src: 'audio/yapping/x.wav' }),
y: new Howl({ src: 'audio/yapping/y.wav' }),
z: new Howl({ src: 'audio/yapping/z.wav' }),
th: new Howl({ src: 'audio/yapping/th.wav' }),
sh: new Howl({ src: 'audio/yapping/sh.wav' }),
_: new Howl({ src: 'audio/yapping/_.wav' }),
let yap_sounds = {}
function loadYapSounds() {
yap_sounds = {
a: new Howl({ src: 'audio/yapping/a.wav' }),
b: new Howl({ src: 'audio/yapping/b.wav' }),
c: new Howl({ src: 'audio/yapping/c.wav' }),
d: new Howl({ src: 'audio/yapping/d.wav' }),
e: new Howl({ src: 'audio/yapping/e.wav' }),
f: new Howl({ src: 'audio/yapping/f.wav' }),
g: new Howl({ src: 'audio/yapping/g.wav' }),
h: new Howl({ src: 'audio/yapping/h.wav' }),
i: new Howl({ src: 'audio/yapping/i.wav' }),
j: new Howl({ src: 'audio/yapping/j.wav' }),
k: new Howl({ src: 'audio/yapping/k.wav' }),
l: new Howl({ src: 'audio/yapping/l.wav' }),
m: new Howl({ src: 'audio/yapping/m.wav' }),
n: new Howl({ src: 'audio/yapping/n.wav' }),
o: new Howl({ src: 'audio/yapping/o.wav' }),
p: new Howl({ src: 'audio/yapping/p.wav' }),
q: new Howl({ src: 'audio/yapping/q.wav' }),
r: new Howl({ src: 'audio/yapping/r.wav' }),
s: new Howl({ src: 'audio/yapping/s.wav' }),
t: new Howl({ src: 'audio/yapping/t.wav' }),
u: new Howl({ src: 'audio/yapping/u.wav' }),
v: new Howl({ src: 'audio/yapping/v.wav' }),
w: new Howl({ src: 'audio/yapping/w.wav' }),
x: new Howl({ src: 'audio/yapping/x.wav' }),
y: new Howl({ src: 'audio/yapping/y.wav' }),
z: new Howl({ src: 'audio/yapping/z.wav' }),
th: new Howl({ src: 'audio/yapping/th.wav' }),
sh: new Howl({ src: 'audio/yapping/sh.wav' }),
_: new Howl({ src: 'audio/yapping/_.wav' }),
}
}

const soundKeys = Object.keys(yap_sounds)
Expand All @@ -52,6 +54,9 @@ async function yap(
} = {},
) {
const yap_queue = []
if (Object.keys(yap_sounds).length === 0) {
loadYapSounds()
}
for (let i = 0; i < text.length; i++) {
const char = text[i]
const lowerChar = char?.toLowerCase()
Expand Down

0 comments on commit 7be8bd3

Please sign in to comment.