create-micdrop 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -2
- package/dist/index.js +1315 -0
- package/package.json +53 -4
- package/templates/expo/App.tsx +123 -0
- package/templates/expo/README.md +65 -0
- package/templates/expo/_env.example +6 -0
- package/templates/expo/_gitignore +7 -0
- package/templates/expo/app.json +34 -0
- package/templates/expo/babel.config.js +6 -0
- package/templates/expo/index.ts +4 -0
- package/templates/expo/package.json +39 -0
- package/templates/expo/server/index.ts +36 -0
- package/templates/expo/server/tsconfig.json +14 -0
- package/templates/expo/src/serverUrl.ts +20 -0
- package/templates/expo/tsconfig.json +8 -0
- package/templates/nextjs/README.md +40 -0
- package/templates/nextjs/_env.example +9 -0
- package/templates/nextjs/_gitignore +7 -0
- package/templates/nextjs/app/CallLoader.tsx +10 -0
- package/templates/nextjs/app/VoiceCall.tsx +71 -0
- package/templates/nextjs/app/globals.css +45 -0
- package/templates/nextjs/app/layout.tsx +16 -0
- package/templates/nextjs/app/page.tsx +10 -0
- package/templates/nextjs/next.config.ts +5 -0
- package/templates/nextjs/package.json +34 -0
- package/templates/nextjs/server/index.ts +35 -0
- package/templates/nextjs/tsconfig.json +25 -0
- package/templates/nextjs/tsconfig.server.json +14 -0
- package/templates/node/README.md +48 -0
- package/templates/node/_env.example +6 -0
- package/templates/node/_gitignore +4 -0
- package/templates/node/package.json +21 -0
- package/templates/node/src/server.ts +34 -0
- package/templates/node/tsconfig.json +14 -0
- package/templates/phone/README.md +86 -0
- package/templates/phone/_env.example +31 -0
- package/templates/phone/_gitignore +5 -0
- package/templates/phone/package.json +25 -0
- package/templates/phone/src/recording.ts +65 -0
- package/templates/phone/src/server.ts +212 -0
- package/templates/phone/src/webhooks.ts +88 -0
- package/templates/phone/telephony/plivo/env.example +6 -0
- package/templates/phone/telephony/plivo/setup.md +7 -0
- package/templates/phone/telephony/plivo/telephony.ts +111 -0
- package/templates/phone/telephony/telnyx/env.example +8 -0
- package/templates/phone/telephony/telnyx/setup.md +9 -0
- package/templates/phone/telephony/telnyx/telephony.ts +107 -0
- package/templates/phone/telephony/twilio/env.example +6 -0
- package/templates/phone/telephony/twilio/setup.md +7 -0
- package/templates/phone/telephony/twilio/telephony.ts +98 -0
- package/templates/phone/telephony/vonage/env.example +7 -0
- package/templates/phone/telephony/vonage/setup.md +15 -0
- package/templates/phone/telephony/vonage/telephony.ts +105 -0
- package/templates/phone/tsconfig.json +14 -0
- package/templates/vite-react/README.md +39 -0
- package/templates/vite-react/_env.example +2 -0
- package/templates/vite-react/_gitignore +4 -0
- package/templates/vite-react/index.html +12 -0
- package/templates/vite-react/package.json +36 -0
- package/templates/vite-react/src/client/App.tsx +75 -0
- package/templates/vite-react/src/client/main.tsx +10 -0
- package/templates/vite-react/src/client/styles.css +45 -0
- package/templates/vite-react/src/server/index.ts +42 -0
- package/templates/vite-react/tsconfig.json +16 -0
- package/templates/vite-react/tsconfig.server.json +14 -0
- package/templates/vite-react/vite.config.ts +23 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "concurrently -n server,client -c blue,green \"npm:dev:server\" \"npm:dev:client\"",
|
|
8
|
+
"dev:server": "tsx watch --env-file=.env src/server/index.ts",
|
|
9
|
+
"dev:client": "vite",
|
|
10
|
+
"build": "vite build",
|
|
11
|
+
"start": "tsx --env-file=.env src/server/index.ts",
|
|
12
|
+
"preview": "vite preview",
|
|
13
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.server.json"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@fastify/websocket": "^11.3.4",
|
|
17
|
+
"@micdrop/react": "*",
|
|
18
|
+
"@micdrop/server": "*",
|
|
19
|
+
"@micdrop/web": "*",
|
|
20
|
+
"fastify": "^5.12.7",
|
|
21
|
+
"onnxruntime-web": "^1.31.1",
|
|
22
|
+
"react": "^19.3.1",
|
|
23
|
+
"react-dom": "^19.3.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.19.13",
|
|
27
|
+
"@types/react": "^19.3.0",
|
|
28
|
+
"@types/react-dom": "^19.3.0",
|
|
29
|
+
"@types/ws": "^8.18.1",
|
|
30
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
31
|
+
"concurrently": "^9.2.1",
|
|
32
|
+
"tsx": "^4.20.6",
|
|
33
|
+
"typescript": "^5.9.3",
|
|
34
|
+
"vite": "^8.3.5"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// A whole voice call in one component. Micdrop takes care of the microphone,
|
|
2
|
+
// the voice activity detection, the speaker and the WebSocket, so this only
|
|
3
|
+
// reads a state and draws it.
|
|
4
|
+
// https://micdrop.dev/docs/client
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
useMicdropEndCall,
|
|
8
|
+
useMicdropError,
|
|
9
|
+
useMicdropState,
|
|
10
|
+
} from '@micdrop/react'
|
|
11
|
+
import { Micdrop, MicdropState } from '@micdrop/web'
|
|
12
|
+
// Silero hears the difference between a voice and a noise
|
|
13
|
+
// https://micdrop.dev/docs/client/vad
|
|
14
|
+
import '@micdrop/web/silero'
|
|
15
|
+
import { useCallback, useState } from 'react'
|
|
16
|
+
|
|
17
|
+
// The call goes through the address of the page, which Vite hands to the
|
|
18
|
+
// server in development
|
|
19
|
+
const SERVER_URL = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}/call`
|
|
20
|
+
|
|
21
|
+
export function App() {
|
|
22
|
+
// Everything about the call lives in this one state
|
|
23
|
+
// https://micdrop.dev/docs/client/react-hooks
|
|
24
|
+
const state = useMicdropState()
|
|
25
|
+
const [error, setError] = useState<string>()
|
|
26
|
+
const isOn = state.isStarted || state.isStarting
|
|
27
|
+
|
|
28
|
+
const handleCall = useCallback(async () => {
|
|
29
|
+
setError(undefined)
|
|
30
|
+
try {
|
|
31
|
+
if (isOn) await Micdrop.stop()
|
|
32
|
+
// Asks for the microphone, connects and starts listening
|
|
33
|
+
else await Micdrop.start({ url: SERVER_URL, vad: ['volume', 'silero'] })
|
|
34
|
+
} catch {
|
|
35
|
+
// Reported by useMicdropError below
|
|
36
|
+
}
|
|
37
|
+
}, [isOn])
|
|
38
|
+
|
|
39
|
+
// The assistant hangs up once the user says goodbye
|
|
40
|
+
useMicdropEndCall(useCallback(() => Micdrop.stopAfterAnswer(), []))
|
|
41
|
+
|
|
42
|
+
// Microphone refused, server unreachable, and so on
|
|
43
|
+
// https://micdrop.dev/docs/client/error-handling
|
|
44
|
+
useMicdropError(
|
|
45
|
+
useCallback((micdropError) => {
|
|
46
|
+
setError(micdropError.message || micdropError.code)
|
|
47
|
+
}, [])
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<main>
|
|
52
|
+
<h1>🖐️🎤 {{ name }}</h1>
|
|
53
|
+
<button onClick={handleCall}>{isOn ? 'Stop call' : 'Start call'}</button>
|
|
54
|
+
<p className="status">{error ?? getStatus(state)}</p>
|
|
55
|
+
<ul className="conversation">
|
|
56
|
+
{state.conversation.map((item, index) =>
|
|
57
|
+
item.role === 'user' || item.role === 'assistant' ? (
|
|
58
|
+
<li key={index} className={item.role}>
|
|
59
|
+
{item.content}
|
|
60
|
+
</li>
|
|
61
|
+
) : null
|
|
62
|
+
)}
|
|
63
|
+
</ul>
|
|
64
|
+
</main>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getStatus(state: MicdropState) {
|
|
69
|
+
if (state.isStarting) return 'Starting the call'
|
|
70
|
+
if (!state.isStarted) return 'Ready'
|
|
71
|
+
if (state.isUserSpeaking) return 'Listening to you'
|
|
72
|
+
if (state.isAssistantSpeaking) return 'Assistant is speaking'
|
|
73
|
+
if (state.isProcessing) return 'Assistant is thinking'
|
|
74
|
+
return 'Your turn'
|
|
75
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
body {
|
|
2
|
+
font-family: system-ui, sans-serif;
|
|
3
|
+
max-width: 36rem;
|
|
4
|
+
margin: 4rem auto;
|
|
5
|
+
padding: 0 1rem;
|
|
6
|
+
color: #111;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
button {
|
|
10
|
+
font: inherit;
|
|
11
|
+
padding: 0.6rem 1.2rem;
|
|
12
|
+
border-radius: 999px;
|
|
13
|
+
border: none;
|
|
14
|
+
background: #6d28d9;
|
|
15
|
+
color: white;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.status {
|
|
20
|
+
color: #666;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.conversation {
|
|
24
|
+
list-style: none;
|
|
25
|
+
padding: 0;
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
gap: 0.5rem;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.conversation li {
|
|
32
|
+
padding: 0.5rem 0.8rem;
|
|
33
|
+
border-radius: 0.8rem;
|
|
34
|
+
max-width: 80%;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.conversation .user {
|
|
38
|
+
align-self: flex-end;
|
|
39
|
+
background: #ede9fe;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.conversation .assistant {
|
|
43
|
+
align-self: flex-start;
|
|
44
|
+
background: #f3f4f6;
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The voice server. Each WebSocket on /call is a call: Micdrop transcribes
|
|
2
|
+
// what the user says, has the agent answer and speaks the answer back.
|
|
3
|
+
// https://micdrop.dev/docs/server/with-fastify
|
|
4
|
+
|
|
5
|
+
import fastifyWebsocket from '@fastify/websocket'
|
|
6
|
+
import { endCallTool, MicdropServer } from '@micdrop/server'
|
|
7
|
+
import Fastify from 'fastify'
|
|
8
|
+
import { createAi } from './ai'
|
|
9
|
+
|
|
10
|
+
const PORT = Number(process.env.PORT || 3001)
|
|
11
|
+
|
|
12
|
+
const fastify = Fastify({ logger: true })
|
|
13
|
+
|
|
14
|
+
// Before the routes: it only upgrades the routes declared after it
|
|
15
|
+
await fastify.register(fastifyWebsocket)
|
|
16
|
+
|
|
17
|
+
fastify.get('/call', { websocket: true }, (socket, request) => {
|
|
18
|
+
new MicdropServer(socket, {
|
|
19
|
+
// The logs of the call go to the logger of Fastify, with the request id
|
|
20
|
+
// https://micdrop.dev/docs/server/logging
|
|
21
|
+
logger: request.log,
|
|
22
|
+
|
|
23
|
+
// Spoken right away, before the user says anything
|
|
24
|
+
// https://micdrop.dev/docs/server/first-message
|
|
25
|
+
firstMessage: 'Hi! What can I do for you?',
|
|
26
|
+
|
|
27
|
+
// The answer shows up in the page as it is written
|
|
28
|
+
// https://micdrop.dev/docs/server/partial-messages
|
|
29
|
+
partialMessages: true,
|
|
30
|
+
|
|
31
|
+
// The providers picked when the project was created, in ai.ts
|
|
32
|
+
...createAi({
|
|
33
|
+
systemPrompt:
|
|
34
|
+
'You are a friendly assistant. Your answers are spoken out loud, so keep them short and conversational.',
|
|
35
|
+
// Lets the assistant hang up once the user says goodbye
|
|
36
|
+
// https://micdrop.dev/docs/server/auto-end-call
|
|
37
|
+
tools: [endCallTool()],
|
|
38
|
+
}),
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
await fastify.listen({ port: PORT, host: '0.0.0.0' })
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["vite/client"],
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noEmit": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/client", "vite.config.ts"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"noEmit": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/server"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { micdrop } from '@micdrop/web/vite'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import { defineConfig } from 'vite'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [
|
|
7
|
+
react(),
|
|
8
|
+
// Ships the Silero model and the ONNX runtime with the app, rather than
|
|
9
|
+
// fetching them from a CDN when a call starts
|
|
10
|
+
// https://micdrop.dev/docs/client/installation#vite-plugin
|
|
11
|
+
micdrop(),
|
|
12
|
+
],
|
|
13
|
+
server: {
|
|
14
|
+
// The page and the call share one address: Vite hands /call to the
|
|
15
|
+
// Fastify server
|
|
16
|
+
proxy: {
|
|
17
|
+
'/call': { target: 'ws://localhost:3001', ws: true },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
build: {
|
|
21
|
+
outDir: 'dist',
|
|
22
|
+
},
|
|
23
|
+
})
|