voice-input 1.0.0__tar.gz
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.
- voice_input-1.0.0/PKG-INFO +294 -0
- voice_input-1.0.0/README.md +262 -0
- voice_input-1.0.0/pyproject.toml +50 -0
- voice_input-1.0.0/setup.cfg +4 -0
- voice_input-1.0.0/voice_input/__init__.py +4 -0
- voice_input-1.0.0/voice_input/__main__.py +5 -0
- voice_input-1.0.0/voice_input/cli.py +158 -0
- voice_input-1.0.0/voice_input/config.py +116 -0
- voice_input-1.0.0/voice_input/server.py +341 -0
- voice_input-1.0.0/voice_input/templates/index.html +570 -0
- voice_input-1.0.0/voice_input/utils.py +55 -0
- voice_input-1.0.0/voice_input.egg-info/PKG-INFO +294 -0
- voice_input-1.0.0/voice_input.egg-info/SOURCES.txt +15 -0
- voice_input-1.0.0/voice_input.egg-info/dependency_links.txt +1 -0
- voice_input-1.0.0/voice_input.egg-info/entry_points.txt +2 -0
- voice_input-1.0.0/voice_input.egg-info/requires.txt +16 -0
- voice_input-1.0.0/voice_input.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: voice-input
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: 跨设备语音输入传输系统 - 将手机端语音识别文本传送到电脑
|
|
5
|
+
Author-email: mofanx <yanwuning@live.cn>
|
|
6
|
+
Maintainer-email: mofanx <yanwuning@live.cn>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/mofanx/voice-input
|
|
9
|
+
Keywords: voice,input,clipboard,cross-device
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Utilities
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: flask>=2.2
|
|
21
|
+
Requires-Dist: pyclip>=0.7
|
|
22
|
+
Provides-Extra: keyboard
|
|
23
|
+
Requires-Dist: keyboard>=0.13; extra == "keyboard"
|
|
24
|
+
Provides-Extra: production
|
|
25
|
+
Requires-Dist: waitress>=2.1; extra == "production"
|
|
26
|
+
Provides-Extra: config
|
|
27
|
+
Requires-Dist: pyyaml>=6.0; extra == "config"
|
|
28
|
+
Provides-Extra: all
|
|
29
|
+
Requires-Dist: keyboard>=0.13; extra == "all"
|
|
30
|
+
Requires-Dist: waitress>=2.1; extra == "all"
|
|
31
|
+
Requires-Dist: pyyaml>=6.0; extra == "all"
|
|
32
|
+
|
|
33
|
+
# 跨设备语音输入传输系统
|
|
34
|
+
|
|
35
|
+
将手机端的语音识别结果,通过局域网实时传送到电脑(Windows / Linux),自动写入剪贴板并可粘贴到当前光标位置。支持任意手机语音输入法(如豆包、讯飞、搜狗、Gboard 等)。
|
|
36
|
+
|
|
37
|
+
## 工作原理
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
手机(语音输入法)→ 局域网 HTTP → 电脑端服务 → 剪贴板 → 可选自动粘贴
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
手机浏览器打开电脑端服务提供的网页,在文本框里用语音输入法输入文字,点击发送或启用自动发送,文本即刻传到电脑剪贴板并可自动粘贴。
|
|
44
|
+
|
|
45
|
+
## 平台支持
|
|
46
|
+
|
|
47
|
+
| 平台 | 仅复制 | 自动粘贴 | 备注 |
|
|
48
|
+
|---|---|---|---|
|
|
49
|
+
| **Windows** | ✅ | ✅ | 无需管理员权限 |
|
|
50
|
+
| **Linux (Xorg)** | ✅ | ✅ | 需要 `sudo` |
|
|
51
|
+
| **Linux (Wayland)** | ✅ | ⚠️ 可能受限 | 建议使用「仅复制」模式 |
|
|
52
|
+
|
|
53
|
+
## 安装
|
|
54
|
+
|
|
55
|
+
### 方式一:pip 安装(推荐)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# 安装基础版(仅复制到剪贴板,不含自动粘贴)
|
|
59
|
+
pip install .
|
|
60
|
+
|
|
61
|
+
# 安装完整版(含自动粘贴 + 生产部署 + YAML 配置)
|
|
62
|
+
pip install ".[all]"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 方式二:直接运行
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install -r requirements.txt
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 快速开始
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Windows
|
|
75
|
+
voice-input -p 8080
|
|
76
|
+
|
|
77
|
+
# Linux(自动粘贴需要 root)
|
|
78
|
+
sudo voice-input -p 8080
|
|
79
|
+
|
|
80
|
+
# 指定端口 + Token
|
|
81
|
+
voice-input -p 9090 -t my-secret-token
|
|
82
|
+
|
|
83
|
+
# 使用配置文件
|
|
84
|
+
voice-input -c config.yaml
|
|
85
|
+
|
|
86
|
+
# python -m 方式
|
|
87
|
+
python -m voice_input -p 8080
|
|
88
|
+
|
|
89
|
+
# 兼容旧入口
|
|
90
|
+
python voice_server.py -p 8080
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
启动后终端会输出:
|
|
94
|
+
```
|
|
95
|
+
============================================================
|
|
96
|
+
跨设备语音输入传输系统 v2.0.0
|
|
97
|
+
============================================================
|
|
98
|
+
服务地址: http://192.168.1.100:8080
|
|
99
|
+
手机页面: http://192.168.1.100:8080/
|
|
100
|
+
Token: 未启用
|
|
101
|
+
============================================================
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**手机端操作**:手机浏览器打开「手机页面」地址,在文本框里用语音输入法输入文字,点发送即可。
|
|
105
|
+
|
|
106
|
+
## 命令行参数
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
用法: voice-input [选项]
|
|
110
|
+
|
|
111
|
+
选项:
|
|
112
|
+
-V, --version 显示版本
|
|
113
|
+
-c, --config FILE YAML 配置文件路径
|
|
114
|
+
-H, --host ADDR 监听地址 (默认 0.0.0.0)
|
|
115
|
+
-p, --port PORT 监听端口 (默认 8080)
|
|
116
|
+
--allowed-ips CIDR IP 白名单,逗号分隔
|
|
117
|
+
-t, --token TOKEN 鉴权 Token
|
|
118
|
+
--require-token 强制启用 Token(未设 --token 时自动生成)
|
|
119
|
+
--no-auto-paste 默认仅复制,不自动粘贴
|
|
120
|
+
--history-size N 历史记录条数 (默认 50)
|
|
121
|
+
--production 使用 waitress 生产服务器
|
|
122
|
+
--workers N 工作线程数 (默认 4)
|
|
123
|
+
--log-level LEVEL 日志级别 (debug/info/warning/error)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 配置文件
|
|
127
|
+
|
|
128
|
+
支持 YAML 格式,参见 `config.example.yaml`:
|
|
129
|
+
|
|
130
|
+
```yaml
|
|
131
|
+
port: 8080
|
|
132
|
+
allowed_ips:
|
|
133
|
+
- "192.168.0.0/16"
|
|
134
|
+
- "10.0.0.0/8"
|
|
135
|
+
token: "your-secret-token"
|
|
136
|
+
require_token: true
|
|
137
|
+
auto_paste: true
|
|
138
|
+
history_size: 50
|
|
139
|
+
log_level: "info"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**优先级**:命令行参数 > 环境变量 > 配置文件 > 默认值
|
|
143
|
+
|
|
144
|
+
### 环境变量
|
|
145
|
+
|
|
146
|
+
所有配置都可通过 `VOICE_INPUT_` 前缀的环境变量设置:
|
|
147
|
+
|
|
148
|
+
| 环境变量 | 说明 |
|
|
149
|
+
|---|---|
|
|
150
|
+
| `VOICE_INPUT_PORT` | 端口 |
|
|
151
|
+
| `VOICE_INPUT_HOST` | 监听地址 |
|
|
152
|
+
| `VOICE_INPUT_TOKEN` | Token |
|
|
153
|
+
| `VOICE_INPUT_REQUIRE_TOKEN` | 是否强制 Token (`1`/`true`) |
|
|
154
|
+
| `VOICE_INPUT_ALLOWED_IPS` | IP 白名单(逗号分隔) |
|
|
155
|
+
| `VOICE_INPUT_AUTO_PASTE` | 默认自动粘贴 (`1`/`true`) |
|
|
156
|
+
| `VOICE_INPUT_HISTORY_SIZE` | 历史条数 |
|
|
157
|
+
| `VOICE_INPUT_LOG_LEVEL` | 日志级别 |
|
|
158
|
+
|
|
159
|
+
## 手机端功能
|
|
160
|
+
|
|
161
|
+
网页端针对手机屏幕优化,支持以下功能:
|
|
162
|
+
|
|
163
|
+
- **发送模式**:仅复制 / 自动粘贴(Ctrl+V)/ 终端粘贴(Ctrl+Shift+V)
|
|
164
|
+
- **自动发送**:开启后,语音输入停顿后自动发送,停顿时间可通过滑块自定义(0.5 - 5 秒)
|
|
165
|
+
- **发送后清空**:发送成功后自动清空输入框,方便连续输入
|
|
166
|
+
- **发送历史**:默认关闭,开启后支持:
|
|
167
|
+
- 关键词搜索
|
|
168
|
+
- 按日期筛选
|
|
169
|
+
- 单条删除 / 清空全部
|
|
170
|
+
- 导出为 JSON 或 CSV 文件
|
|
171
|
+
- **设置持久化**:Token、模式、开关、延迟时间等自动保存到浏览器 localStorage
|
|
172
|
+
- **响应式布局**:自适应不同手机屏幕尺寸,支持竖屏与横屏
|
|
173
|
+
|
|
174
|
+
## 生产部署
|
|
175
|
+
|
|
176
|
+
### 使用 waitress
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# Windows
|
|
180
|
+
voice-input --production --workers 4 -t my-token
|
|
181
|
+
|
|
182
|
+
# Linux
|
|
183
|
+
sudo voice-input --production --workers 4 -t my-token
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### systemd 服务(Linux)
|
|
187
|
+
|
|
188
|
+
创建 `/etc/systemd/system/voice-input.service`:
|
|
189
|
+
|
|
190
|
+
```ini
|
|
191
|
+
[Unit]
|
|
192
|
+
Description=Voice Input Server
|
|
193
|
+
After=network.target
|
|
194
|
+
|
|
195
|
+
[Service]
|
|
196
|
+
Type=simple
|
|
197
|
+
User=root
|
|
198
|
+
ExecStart=/usr/local/bin/voice-input --production -c /etc/voice-input/config.yaml
|
|
199
|
+
Restart=on-failure
|
|
200
|
+
RestartSec=5
|
|
201
|
+
|
|
202
|
+
[Install]
|
|
203
|
+
WantedBy=multi-user.target
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
sudo systemctl daemon-reload
|
|
208
|
+
sudo systemctl enable --now voice-input
|
|
209
|
+
sudo systemctl status voice-input
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## API 接口
|
|
213
|
+
|
|
214
|
+
| 路径 | 方法 | 说明 |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| `/` | GET | 手机端输入页面 |
|
|
217
|
+
| `/status` | GET | 服务状态 |
|
|
218
|
+
| `/history` | GET | 发送历史列表 |
|
|
219
|
+
| `/history/<id>` | DELETE | 删除单条历史 |
|
|
220
|
+
| `/history` | DELETE | 清空全部历史 |
|
|
221
|
+
| `/history/export` | GET | 导出历史(?format=json 或 csv) |
|
|
222
|
+
| `/input` | POST | 接收文本 |
|
|
223
|
+
|
|
224
|
+
### POST /input
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"text": "要发送的文本",
|
|
229
|
+
"action": "paste",
|
|
230
|
+
"device_id": "phone_web",
|
|
231
|
+
"timestamp": 1700000000000
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**action 取值**:
|
|
236
|
+
- `copy` — 仅复制到剪贴板
|
|
237
|
+
- `paste` — 复制 + Ctrl+V
|
|
238
|
+
- `paste_terminal` — 复制 + Ctrl+Shift+V(Linux);Windows 下等同 paste
|
|
239
|
+
- `type` — 逐字键入
|
|
240
|
+
|
|
241
|
+
**鉴权**:Token 可通过 `X-Auth-Token` Header、`?token=` Query 参数或 Body 中 `token` 字段传递。
|
|
242
|
+
|
|
243
|
+
## 常见问题
|
|
244
|
+
|
|
245
|
+
### 自动粘贴不生效
|
|
246
|
+
|
|
247
|
+
- **Linux**:`keyboard` 库需要 root 权限,请用 `sudo` 运行
|
|
248
|
+
- **Linux Wayland**:模拟按键可能不稳定,建议切换到 Xorg 会话,或使用「仅复制」模式后手动 Ctrl+V
|
|
249
|
+
- **Windows**:通常无需特殊权限,如仍不生效请以管理员身份运行
|
|
250
|
+
- 确保发送时电脑端目标输入框处于焦点状态
|
|
251
|
+
|
|
252
|
+
### 手机连不上
|
|
253
|
+
|
|
254
|
+
- 确保手机和电脑在同一局域网 / Wi-Fi
|
|
255
|
+
- 检查防火墙:
|
|
256
|
+
- Linux:`sudo ufw allow 8080/tcp`
|
|
257
|
+
- Windows:在「Windows Defender 防火墙」中放行对应端口
|
|
258
|
+
- 检查 IP 白名单配置是否包含手机所在网段
|
|
259
|
+
|
|
260
|
+
### 打包发布
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
pip install build
|
|
264
|
+
python -m build
|
|
265
|
+
|
|
266
|
+
# 生成的包在 dist/ 目录
|
|
267
|
+
# dist/voice_input-2.0.0-py3-none-any.whl
|
|
268
|
+
# dist/voice_input-2.0.0.tar.gz
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## 项目结构
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
db_voice_input/
|
|
275
|
+
├── pyproject.toml # 打包配置
|
|
276
|
+
├── requirements.txt # 依赖清单
|
|
277
|
+
├── README.md # 本文档
|
|
278
|
+
├── config.example.yaml # 配置文件示例
|
|
279
|
+
├── .gitignore # Git 忽略规则
|
|
280
|
+
├── voice_server.py # 兼容旧入口
|
|
281
|
+
└── voice_input/ # Python 包
|
|
282
|
+
├── __init__.py # 包信息与版本
|
|
283
|
+
├── __main__.py # python -m 入口
|
|
284
|
+
├── cli.py # 命令行解析与启动
|
|
285
|
+
├── config.py # 配置管理(YAML/环境变量/CLI 三级合并)
|
|
286
|
+
├── server.py # Flask 应用与路由
|
|
287
|
+
├── utils.py # 工具函数
|
|
288
|
+
└── templates/
|
|
289
|
+
└── index.html # 手机端 UI(响应式)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## License
|
|
293
|
+
|
|
294
|
+
MIT
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# 跨设备语音输入传输系统
|
|
2
|
+
|
|
3
|
+
将手机端的语音识别结果,通过局域网实时传送到电脑(Windows / Linux),自动写入剪贴板并可粘贴到当前光标位置。支持任意手机语音输入法(如豆包、讯飞、搜狗、Gboard 等)。
|
|
4
|
+
|
|
5
|
+
## 工作原理
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
手机(语音输入法)→ 局域网 HTTP → 电脑端服务 → 剪贴板 → 可选自动粘贴
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
手机浏览器打开电脑端服务提供的网页,在文本框里用语音输入法输入文字,点击发送或启用自动发送,文本即刻传到电脑剪贴板并可自动粘贴。
|
|
12
|
+
|
|
13
|
+
## 平台支持
|
|
14
|
+
|
|
15
|
+
| 平台 | 仅复制 | 自动粘贴 | 备注 |
|
|
16
|
+
|---|---|---|---|
|
|
17
|
+
| **Windows** | ✅ | ✅ | 无需管理员权限 |
|
|
18
|
+
| **Linux (Xorg)** | ✅ | ✅ | 需要 `sudo` |
|
|
19
|
+
| **Linux (Wayland)** | ✅ | ⚠️ 可能受限 | 建议使用「仅复制」模式 |
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
### 方式一:pip 安装(推荐)
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 安装基础版(仅复制到剪贴板,不含自动粘贴)
|
|
27
|
+
pip install .
|
|
28
|
+
|
|
29
|
+
# 安装完整版(含自动粘贴 + 生产部署 + YAML 配置)
|
|
30
|
+
pip install ".[all]"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 方式二:直接运行
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -r requirements.txt
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 快速开始
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Windows
|
|
43
|
+
voice-input -p 8080
|
|
44
|
+
|
|
45
|
+
# Linux(自动粘贴需要 root)
|
|
46
|
+
sudo voice-input -p 8080
|
|
47
|
+
|
|
48
|
+
# 指定端口 + Token
|
|
49
|
+
voice-input -p 9090 -t my-secret-token
|
|
50
|
+
|
|
51
|
+
# 使用配置文件
|
|
52
|
+
voice-input -c config.yaml
|
|
53
|
+
|
|
54
|
+
# python -m 方式
|
|
55
|
+
python -m voice_input -p 8080
|
|
56
|
+
|
|
57
|
+
# 兼容旧入口
|
|
58
|
+
python voice_server.py -p 8080
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
启动后终端会输出:
|
|
62
|
+
```
|
|
63
|
+
============================================================
|
|
64
|
+
跨设备语音输入传输系统 v2.0.0
|
|
65
|
+
============================================================
|
|
66
|
+
服务地址: http://192.168.1.100:8080
|
|
67
|
+
手机页面: http://192.168.1.100:8080/
|
|
68
|
+
Token: 未启用
|
|
69
|
+
============================================================
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**手机端操作**:手机浏览器打开「手机页面」地址,在文本框里用语音输入法输入文字,点发送即可。
|
|
73
|
+
|
|
74
|
+
## 命令行参数
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
用法: voice-input [选项]
|
|
78
|
+
|
|
79
|
+
选项:
|
|
80
|
+
-V, --version 显示版本
|
|
81
|
+
-c, --config FILE YAML 配置文件路径
|
|
82
|
+
-H, --host ADDR 监听地址 (默认 0.0.0.0)
|
|
83
|
+
-p, --port PORT 监听端口 (默认 8080)
|
|
84
|
+
--allowed-ips CIDR IP 白名单,逗号分隔
|
|
85
|
+
-t, --token TOKEN 鉴权 Token
|
|
86
|
+
--require-token 强制启用 Token(未设 --token 时自动生成)
|
|
87
|
+
--no-auto-paste 默认仅复制,不自动粘贴
|
|
88
|
+
--history-size N 历史记录条数 (默认 50)
|
|
89
|
+
--production 使用 waitress 生产服务器
|
|
90
|
+
--workers N 工作线程数 (默认 4)
|
|
91
|
+
--log-level LEVEL 日志级别 (debug/info/warning/error)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 配置文件
|
|
95
|
+
|
|
96
|
+
支持 YAML 格式,参见 `config.example.yaml`:
|
|
97
|
+
|
|
98
|
+
```yaml
|
|
99
|
+
port: 8080
|
|
100
|
+
allowed_ips:
|
|
101
|
+
- "192.168.0.0/16"
|
|
102
|
+
- "10.0.0.0/8"
|
|
103
|
+
token: "your-secret-token"
|
|
104
|
+
require_token: true
|
|
105
|
+
auto_paste: true
|
|
106
|
+
history_size: 50
|
|
107
|
+
log_level: "info"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**优先级**:命令行参数 > 环境变量 > 配置文件 > 默认值
|
|
111
|
+
|
|
112
|
+
### 环境变量
|
|
113
|
+
|
|
114
|
+
所有配置都可通过 `VOICE_INPUT_` 前缀的环境变量设置:
|
|
115
|
+
|
|
116
|
+
| 环境变量 | 说明 |
|
|
117
|
+
|---|---|
|
|
118
|
+
| `VOICE_INPUT_PORT` | 端口 |
|
|
119
|
+
| `VOICE_INPUT_HOST` | 监听地址 |
|
|
120
|
+
| `VOICE_INPUT_TOKEN` | Token |
|
|
121
|
+
| `VOICE_INPUT_REQUIRE_TOKEN` | 是否强制 Token (`1`/`true`) |
|
|
122
|
+
| `VOICE_INPUT_ALLOWED_IPS` | IP 白名单(逗号分隔) |
|
|
123
|
+
| `VOICE_INPUT_AUTO_PASTE` | 默认自动粘贴 (`1`/`true`) |
|
|
124
|
+
| `VOICE_INPUT_HISTORY_SIZE` | 历史条数 |
|
|
125
|
+
| `VOICE_INPUT_LOG_LEVEL` | 日志级别 |
|
|
126
|
+
|
|
127
|
+
## 手机端功能
|
|
128
|
+
|
|
129
|
+
网页端针对手机屏幕优化,支持以下功能:
|
|
130
|
+
|
|
131
|
+
- **发送模式**:仅复制 / 自动粘贴(Ctrl+V)/ 终端粘贴(Ctrl+Shift+V)
|
|
132
|
+
- **自动发送**:开启后,语音输入停顿后自动发送,停顿时间可通过滑块自定义(0.5 - 5 秒)
|
|
133
|
+
- **发送后清空**:发送成功后自动清空输入框,方便连续输入
|
|
134
|
+
- **发送历史**:默认关闭,开启后支持:
|
|
135
|
+
- 关键词搜索
|
|
136
|
+
- 按日期筛选
|
|
137
|
+
- 单条删除 / 清空全部
|
|
138
|
+
- 导出为 JSON 或 CSV 文件
|
|
139
|
+
- **设置持久化**:Token、模式、开关、延迟时间等自动保存到浏览器 localStorage
|
|
140
|
+
- **响应式布局**:自适应不同手机屏幕尺寸,支持竖屏与横屏
|
|
141
|
+
|
|
142
|
+
## 生产部署
|
|
143
|
+
|
|
144
|
+
### 使用 waitress
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Windows
|
|
148
|
+
voice-input --production --workers 4 -t my-token
|
|
149
|
+
|
|
150
|
+
# Linux
|
|
151
|
+
sudo voice-input --production --workers 4 -t my-token
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### systemd 服务(Linux)
|
|
155
|
+
|
|
156
|
+
创建 `/etc/systemd/system/voice-input.service`:
|
|
157
|
+
|
|
158
|
+
```ini
|
|
159
|
+
[Unit]
|
|
160
|
+
Description=Voice Input Server
|
|
161
|
+
After=network.target
|
|
162
|
+
|
|
163
|
+
[Service]
|
|
164
|
+
Type=simple
|
|
165
|
+
User=root
|
|
166
|
+
ExecStart=/usr/local/bin/voice-input --production -c /etc/voice-input/config.yaml
|
|
167
|
+
Restart=on-failure
|
|
168
|
+
RestartSec=5
|
|
169
|
+
|
|
170
|
+
[Install]
|
|
171
|
+
WantedBy=multi-user.target
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
sudo systemctl daemon-reload
|
|
176
|
+
sudo systemctl enable --now voice-input
|
|
177
|
+
sudo systemctl status voice-input
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## API 接口
|
|
181
|
+
|
|
182
|
+
| 路径 | 方法 | 说明 |
|
|
183
|
+
|---|---|---|
|
|
184
|
+
| `/` | GET | 手机端输入页面 |
|
|
185
|
+
| `/status` | GET | 服务状态 |
|
|
186
|
+
| `/history` | GET | 发送历史列表 |
|
|
187
|
+
| `/history/<id>` | DELETE | 删除单条历史 |
|
|
188
|
+
| `/history` | DELETE | 清空全部历史 |
|
|
189
|
+
| `/history/export` | GET | 导出历史(?format=json 或 csv) |
|
|
190
|
+
| `/input` | POST | 接收文本 |
|
|
191
|
+
|
|
192
|
+
### POST /input
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"text": "要发送的文本",
|
|
197
|
+
"action": "paste",
|
|
198
|
+
"device_id": "phone_web",
|
|
199
|
+
"timestamp": 1700000000000
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**action 取值**:
|
|
204
|
+
- `copy` — 仅复制到剪贴板
|
|
205
|
+
- `paste` — 复制 + Ctrl+V
|
|
206
|
+
- `paste_terminal` — 复制 + Ctrl+Shift+V(Linux);Windows 下等同 paste
|
|
207
|
+
- `type` — 逐字键入
|
|
208
|
+
|
|
209
|
+
**鉴权**:Token 可通过 `X-Auth-Token` Header、`?token=` Query 参数或 Body 中 `token` 字段传递。
|
|
210
|
+
|
|
211
|
+
## 常见问题
|
|
212
|
+
|
|
213
|
+
### 自动粘贴不生效
|
|
214
|
+
|
|
215
|
+
- **Linux**:`keyboard` 库需要 root 权限,请用 `sudo` 运行
|
|
216
|
+
- **Linux Wayland**:模拟按键可能不稳定,建议切换到 Xorg 会话,或使用「仅复制」模式后手动 Ctrl+V
|
|
217
|
+
- **Windows**:通常无需特殊权限,如仍不生效请以管理员身份运行
|
|
218
|
+
- 确保发送时电脑端目标输入框处于焦点状态
|
|
219
|
+
|
|
220
|
+
### 手机连不上
|
|
221
|
+
|
|
222
|
+
- 确保手机和电脑在同一局域网 / Wi-Fi
|
|
223
|
+
- 检查防火墙:
|
|
224
|
+
- Linux:`sudo ufw allow 8080/tcp`
|
|
225
|
+
- Windows:在「Windows Defender 防火墙」中放行对应端口
|
|
226
|
+
- 检查 IP 白名单配置是否包含手机所在网段
|
|
227
|
+
|
|
228
|
+
### 打包发布
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
pip install build
|
|
232
|
+
python -m build
|
|
233
|
+
|
|
234
|
+
# 生成的包在 dist/ 目录
|
|
235
|
+
# dist/voice_input-2.0.0-py3-none-any.whl
|
|
236
|
+
# dist/voice_input-2.0.0.tar.gz
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## 项目结构
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
db_voice_input/
|
|
243
|
+
├── pyproject.toml # 打包配置
|
|
244
|
+
├── requirements.txt # 依赖清单
|
|
245
|
+
├── README.md # 本文档
|
|
246
|
+
├── config.example.yaml # 配置文件示例
|
|
247
|
+
├── .gitignore # Git 忽略规则
|
|
248
|
+
├── voice_server.py # 兼容旧入口
|
|
249
|
+
└── voice_input/ # Python 包
|
|
250
|
+
├── __init__.py # 包信息与版本
|
|
251
|
+
├── __main__.py # python -m 入口
|
|
252
|
+
├── cli.py # 命令行解析与启动
|
|
253
|
+
├── config.py # 配置管理(YAML/环境变量/CLI 三级合并)
|
|
254
|
+
├── server.py # Flask 应用与路由
|
|
255
|
+
├── utils.py # 工具函数
|
|
256
|
+
└── templates/
|
|
257
|
+
└── index.html # 手机端 UI(响应式)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
|
|
262
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "voice-input"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "跨设备语音输入传输系统 - 将手机端语音识别文本传送到电脑"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "mofanx", email = "yanwuning@live.cn"}
|
|
13
|
+
]
|
|
14
|
+
maintainers = [
|
|
15
|
+
{name = "mofanx", email = "yanwuning@live.cn"}
|
|
16
|
+
]
|
|
17
|
+
requires-python = ">=3.8"
|
|
18
|
+
keywords = ["voice", "input", "clipboard", "cross-device"]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Environment :: Console",
|
|
22
|
+
"Intended Audience :: End Users/Desktop",
|
|
23
|
+
"License :: OSI Approved :: MIT License",
|
|
24
|
+
"Operating System :: POSIX :: Linux",
|
|
25
|
+
"Operating System :: Microsoft :: Windows",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Topic :: Utilities",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"flask>=2.2",
|
|
31
|
+
"pyclip>=0.7",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
keyboard = ["keyboard>=0.13"]
|
|
36
|
+
production = ["waitress>=2.1"]
|
|
37
|
+
config = ["pyyaml>=6.0"]
|
|
38
|
+
all = ["keyboard>=0.13", "waitress>=2.1", "pyyaml>=6.0"]
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
voice-input = "voice_input.cli:main"
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://github.com/mofanx/voice-input"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
include = ["voice_input*"]
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.package-data]
|
|
50
|
+
voice_input = ["templates/*.html"]
|