MCPcopy Create free account
hub / github.com/FunAudioLLM/Fun-Audio-Chat / Queue

Function Queue

web_demo/client/src/pages/Queue/Queue.tsx:19–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17}
18
19export const Queue: FC = () => {
20 const [searchParams] = useSearchParams();
21 const overrideWorkerAddr = searchParams.get("worker_addr");
22 const [hasMicrophoneAccess, setHasMicrophoneAccess] = useState<boolean>(false);
23 const [showMicrophoneAccessMessage, setShowMicrophoneAccessMessage] = useState<boolean>(false);
24 const [shouldConnect, setShouldConnect] = useState<boolean>(false);
25 const [connectionMode, setConnectionMode] = useState<ConversationMode | null>(null);
26 const [systemPrompt, setSystemPrompt] = useState<string>("");
27 const modelParams = useModelParams({
28 textTemperature: getFloatFromStorage(localStorage.getItem("textTemperature")),
29 textTopk: getIntFromStorage(localStorage.getItem("textTopk")),
30 audioTemperature: getFloatFromStorage(localStorage.getItem("audioTemperature")),
31 audioTopk: getIntFromStorage(localStorage.getItem("audioTopk")),
32 padMult: getFloatFromStorage(localStorage.getItem("padMult")),
33 repetitionPenalty: getFloatFromStorage(localStorage.getItem("repetitionPenalty")),
34 repetitionPenaltyContext: getIntFromStorage(localStorage.getItem("repetitionPenaltyContext")),
35 imageResolution: getIntFromStorage(localStorage.getItem("imageResolution"))
36 });
37
38 const audioContext = useRef<AudioContext | null>(null);
39 const worklet = useRef<AudioWorkletNode | null>(null);
40 // enable eruda in development
41 useEffect(() => {
42 if (env.VITE_ENV === "development") {
43 eruda.init();
44 }
45 () => {
46 if (env.VITE_ENV === "development") {
47 eruda.destroy();
48 }
49 };
50 }, []);
51
52 const getMicrophoneAccess = useCallback(async () => {
53 try {
54 await window.navigator.mediaDevices.getUserMedia({ audio: true });
55 setHasMicrophoneAccess(true);
56 return true;
57 } catch (e) {
58 console.error(e);
59 setShowMicrophoneAccessMessage(true);
60 setHasMicrophoneAccess(false);
61 }
62 return false;
63 }, [setHasMicrophoneAccess, setShowMicrophoneAccessMessage]);
64
65 const startProcessor = useCallback(async () => {
66 if (!audioContext.current) {
67 audioContext.current = new AudioContext();
68 }
69 if (worklet.current) {
70 return;
71 }
72 let ctx = audioContext.current;
73 ctx.resume();
74 try {
75 worklet.current = new AudioWorkletNode(ctx, 'moshi-processor');
76 } catch (err) {

Callers

nothing calls this directly

Calls 3

useModelParamsFunction · 0.90
getFloatFromStorageFunction · 0.85
getIntFromStorageFunction · 0.85

Tested by

no test coverage detected