voice-page-agent 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 +151 -0
- package/dist/index.cjs +603 -0
- package/dist/index.d.cts +151 -0
- package/dist/index.d.ts +151 -0
- package/dist/index.js +596 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# voice-page-agent
|
|
2
|
+
|
|
3
|
+
`voice-page-agent` is a Vue2/Vue3 compatible plugin that adds wake-word voice control for [page-agent](https://www.npmjs.com/package/page-agent).
|
|
4
|
+
|
|
5
|
+
Wake flow:
|
|
6
|
+
- wait for wake word (default: `布丁布丁`)
|
|
7
|
+
- transcribe command by browser SpeechRecognition
|
|
8
|
+
- call `pageAgent.execute(command)`
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i voice-page-agent page-agent vue-demi
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
For Vue2, also install composition plugin:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm i @vue/composition-api
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Option Format
|
|
23
|
+
|
|
24
|
+
Use this shape:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
{
|
|
28
|
+
pageAgent: {
|
|
29
|
+
// all page-agent options
|
|
30
|
+
baseURL: "https://your-api.example.com",
|
|
31
|
+
model: "qwen3.5-plus",
|
|
32
|
+
apiKey: "NA",
|
|
33
|
+
language: "zh-CN",
|
|
34
|
+
// ...any other page-agent options
|
|
35
|
+
},
|
|
36
|
+
wakeWord: "布丁布丁", // string or string[]
|
|
37
|
+
enableHomophoneMatch: true, // whether homophone fuzzy match is enabled
|
|
38
|
+
wakeCooldownMs: 1400, // wake debounce
|
|
39
|
+
commandInitialTimeoutMs: 12000, // how long to wait for first command after wake
|
|
40
|
+
commandSilenceTimeoutMs: 2600, // silence timeout between phrases
|
|
41
|
+
commandMaxWindowMs: 22000, // max command listening window
|
|
42
|
+
recognitionLang: "zh-CN", // SpeechRecognition language
|
|
43
|
+
showAgentWhenWake: true, // auto-open panel when wake hit
|
|
44
|
+
autoStart: false // start wake on init
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Vue3 Usage
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { createApp } from "vue";
|
|
52
|
+
import App from "./App.vue";
|
|
53
|
+
import VoicePageAgentPlugin from "voice-page-agent";
|
|
54
|
+
|
|
55
|
+
const app = createApp(App);
|
|
56
|
+
app.use(VoicePageAgentPlugin, {
|
|
57
|
+
pageAgent: {
|
|
58
|
+
baseURL: "https://your-api.example.com",
|
|
59
|
+
model: "qwen3.5-plus",
|
|
60
|
+
apiKey: "NA",
|
|
61
|
+
language: "zh-CN",
|
|
62
|
+
},
|
|
63
|
+
wakeWord: "布丁布丁",
|
|
64
|
+
enableHomophoneMatch: true,
|
|
65
|
+
});
|
|
66
|
+
app.mount("#app");
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Use in component:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { useVoicePageAgent } from "voice-page-agent";
|
|
73
|
+
|
|
74
|
+
const controller = useVoicePageAgent();
|
|
75
|
+
await controller.startWake();
|
|
76
|
+
await controller.openAgent();
|
|
77
|
+
await controller.runCommand("打开工具页面");
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Vue2 Usage
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import Vue from "vue";
|
|
84
|
+
import CompositionApi from "@vue/composition-api";
|
|
85
|
+
import VoicePageAgentPlugin from "voice-page-agent";
|
|
86
|
+
|
|
87
|
+
Vue.use(CompositionApi);
|
|
88
|
+
Vue.use(VoicePageAgentPlugin, {
|
|
89
|
+
pageAgent: {
|
|
90
|
+
baseURL: "https://your-api.example.com",
|
|
91
|
+
model: "qwen3.5-plus",
|
|
92
|
+
apiKey: "NA",
|
|
93
|
+
language: "zh-CN",
|
|
94
|
+
},
|
|
95
|
+
wakeWord: "布丁布丁",
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Then:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
this.$voicePageAgent.startWake();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Built-in Component
|
|
106
|
+
|
|
107
|
+
You can use `VoicePageAgentButton` globally after plugin install:
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<VoicePageAgentButton />
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
It renders:
|
|
114
|
+
- wake button (only when mic permission is not granted)
|
|
115
|
+
- open page-agent button
|
|
116
|
+
- status text
|
|
117
|
+
|
|
118
|
+
## API
|
|
119
|
+
|
|
120
|
+
`VoicePageAgentController`:
|
|
121
|
+
- `startWake(): Promise<void>`
|
|
122
|
+
- `stopWake(): void`
|
|
123
|
+
- `openAgent(): Promise<RuntimePageAgent | null>`
|
|
124
|
+
- `runCommand(text: string): Promise<void>`
|
|
125
|
+
- `dispose(): void`
|
|
126
|
+
- `onStateChange(listener): () => void`
|
|
127
|
+
- `snapshot` (current state)
|
|
128
|
+
|
|
129
|
+
## Local Examples
|
|
130
|
+
|
|
131
|
+
This repo includes runnable examples:
|
|
132
|
+
|
|
133
|
+
- `examples/vue3`
|
|
134
|
+
- `examples/vue2`
|
|
135
|
+
|
|
136
|
+
Run Vue3 demo:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
cd examples/vue3
|
|
140
|
+
npm i
|
|
141
|
+
npm run dev
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Run Vue2 demo:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
cd examples/vue2
|
|
148
|
+
npm i
|
|
149
|
+
npm run dev
|
|
150
|
+
```
|
|
151
|
+
|