Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starter Project #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions app/api/assemblyToken/route.ts

This file was deleted.

31 changes: 0 additions & 31 deletions app/api/lemurRequest/route.ts

This file was deleted.

131 changes: 1 addition & 130 deletions components/CallLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use client';

import Image from 'next/image';
import { createMicrophone } from '@/helpers/createMicrophone';
import { createTranscriber } from '@/helpers/createTranscriber';
import { CallingState } from '@stream-io/video-client';
import {
useCallStateHooks,
Expand All @@ -11,86 +8,12 @@ import {
CallControls,
} from '@stream-io/video-react-sdk';
import '@stream-io/video-react-sdk/dist/css/styles.css';
import { useCallback, useEffect, useState } from 'react';
import robotImage from '../assets/robot.png';
import llamaImage from '../assets/llama.png';
import { RealtimeTranscriber } from 'assemblyai';

export default function CallLayout(): JSX.Element {
// Text to display what is transcribed from AssemblyAI
const [transcribedText, setTranscribedText] = useState<string>('');
const [robotActive, setRobotActive] = useState<boolean>(false);
const [llamaActive, setLlamaActive] = useState<boolean>(false);
const [llamaResponse, setLlamaResponse] = useState<string>('');
const [transcriber, setTranscriber] = useState<
RealtimeTranscriber | undefined
>(undefined);
const [mic, setMic] = useState<
| {
startRecording(onAudioCallback: any): Promise<void>;
stopRecording(): void;
}
| undefined
>(undefined);

// Collecting data from the Stream SDK using hooks
const { useCallCallingState, useParticipantCount, useMicrophoneState } =
useCallStateHooks();
const { useCallCallingState, useParticipantCount } = useCallStateHooks();
const participantCount = useParticipantCount();
const callingState = useCallCallingState();
const { mediaStream } = useMicrophoneState();

const processPrompt = useCallback(async function processPrompt(
prompt: string
) {
const response = await fetch('/api/lemurRequest', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: prompt }),
});

const responseBody = await response.json();
const lemurResponse = responseBody.response;
console.log(lemurResponse);
setLlamaResponse(lemurResponse);

setTimeout(() => {
setLlamaResponse('');
setLlamaActive(false);
setTranscribedText('');
}, 7000);
},
[]);

const initializeAssemblyAI = useCallback(
async function initializeAssemblyAI() {
const transcriber = await createTranscriber(
setTranscribedText,
setLlamaActive,
processPrompt
);

if (!transcriber) {
console.error('Transcriber is not created');
return;
}
await transcriber.connect();

if (!mediaStream) {
console.error('No media stream found');
return;
}
const mic = createMicrophone(mediaStream);
console.log('Mic: ', mic, ', starting recording');
mic.startRecording((audioData: any) => {
// console.log('[Option 2] Audio data: ', audioData);
transcriber.sendAudio(audioData);
});
setMic(mic);
setTranscriber(transcriber);
},
[mediaStream, processPrompt]
);

if (callingState !== CallingState.JOINED) {
return (
Expand All @@ -105,62 +28,10 @@ export default function CallLayout(): JSX.Element {
<h2>Participants: {participantCount}</h2>
<div className='relative overflow-hidden rounded-xl'>
<SpeakerLayout participantsBarPosition='bottom' />
{llamaResponse && (
<div className='absolute mx-8 top-8 right-8 bg-white text-black p-4 rounded-lg shadow-md'>
{llamaResponse}
</div>
)}
<div className='flex items-center justify-center w-full absolute bottom-2'>
<h3 className='text-white text-center bg-black rounded-xl px-6 py-1'>
{transcribedText}
</h3>
</div>
<div
className={`absolute transition ease-in-out duration-300 bottom-1 right-4 ${
llamaActive
? 'translate-x-0 translate-y-0 opacity-100'
: 'translate-x-60 translate-y-60 opacity-0'
}`}
>
<Image
src={llamaImage}
width={200}
height={200}
alt='llama'
className='relative'
/>
</div>
</div>
<div className='flex items-center justify-between mx-4'>
<CallControls />
<button className='ml-8' onClick={() => switchRobot(robotActive)}>
<Image
src={robotImage}
width={50}
height={50}
alt='robot'
className={`border-2 border-black dark:bg-white rounded-full transition-colors ease-in-out duration-200 ${
robotActive ? 'bg-black animate-pulse' : ''
}`}
/>
</button>
</div>
</StreamTheme>
);

async function switchRobot(isActive: boolean) {
if (isActive) {
console.log('Robot is active');
mic?.stopRecording();
await transcriber?.close(false);
setMic(undefined);
setTranscriber(undefined);
setRobotActive(false);
} else {
console.log('Robot is inactive');
await initializeAssemblyAI();
console.log('Initialized Assembly AI');
setRobotActive(true);
}
}
}
47 changes: 0 additions & 47 deletions helpers/createMicrophone.ts

This file was deleted.

74 changes: 0 additions & 74 deletions helpers/createTranscriber.ts

This file was deleted.

11 changes: 0 additions & 11 deletions helpers/getAssemblyToken.ts

This file was deleted.

6 changes: 0 additions & 6 deletions helpers/mergeBuffers.ts

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"dependencies": {
"@stream-io/node-sdk": "^0.1.13",
"@stream-io/video-react-sdk": "^0.6.10",
"assemblyai": "^4.4.1",
"next": "14.2.2",
"react": "^18",
"react-dom": "^18"
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,6 @@ arraybuffer.prototype.slice@^1.0.3:
is-array-buffer "^3.0.4"
is-shared-array-buffer "^1.0.2"

assemblyai@^4.4.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/assemblyai/-/assemblyai-4.4.1.tgz#9534a604cc189377fcea6d8149427483367c5da5"
integrity sha512-GzpbSRhZ0VlHNTQTOKxOrod3Ckw4AZVQQlnE5sJeCuAhTXJLLi5SE6U4vOapTsxf3lO7+93tdNTlWBrkwYO4Nw==
dependencies:
ws "^8.16.0"

ast-types-flow@^0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/ast-types-flow/-/ast-types-flow-0.0.8.tgz#0a85e1c92695769ac13a428bb653e7538bea27d6"
Expand Down Expand Up @@ -3039,7 +3032,7 @@ wrappy@1:
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==

ws@^8.14.2, ws@^8.16.0:
ws@^8.14.2:
version "8.16.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4"
integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==
Expand Down