Initial commit
This commit is contained in:
170
developer-front/public/docs/api-reference.md
Normal file
170
developer-front/public/docs/api-reference.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# API 参考
|
||||
|
||||
完整的 API 接口文档。
|
||||
|
||||
## 显示 API
|
||||
|
||||
在眼镜显示屏上显示内容。
|
||||
|
||||
### showText(options)
|
||||
|
||||
显示文本内容。
|
||||
|
||||
**参数:**
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| text | string | 是 | 要显示的文本 |
|
||||
| position | object | 否 | 显示位置 {x, y} |
|
||||
| fontSize | number | 否 | 字体大小,默认 24 |
|
||||
| color | string | 否 | 颜色,默认 '#FFFFFF' |
|
||||
| duration | number | 否 | 显示时长(毫秒),0 表示永久显示 |
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
glasses.display.showText({
|
||||
text: 'Hello World',
|
||||
position: { x: 100, y: 200 },
|
||||
fontSize: 24,
|
||||
color: '#FFFFFF',
|
||||
duration: 3000
|
||||
})
|
||||
```
|
||||
|
||||
### showImage(options)
|
||||
|
||||
显示图像。
|
||||
|
||||
**参数:**
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| url | string | 是 | 图像 URL |
|
||||
| position | object | 否 | 显示位置 {x, y} |
|
||||
| width | number | 否 | 宽度 |
|
||||
| height | number | 否 | 高度 |
|
||||
| opacity | number | 否 | 透明度,0-1 |
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
glasses.display.showImage({
|
||||
url: 'https://example.com/image.png',
|
||||
position: { x: 50, y: 100 },
|
||||
width: 200,
|
||||
height: 150,
|
||||
opacity: 0.8
|
||||
})
|
||||
```
|
||||
|
||||
### clear()
|
||||
|
||||
清除所有显示内容。
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
glasses.display.clear()
|
||||
```
|
||||
|
||||
## 语音 API
|
||||
|
||||
语音识别和合成。
|
||||
|
||||
### startRecognition(options)
|
||||
|
||||
启动语音识别。
|
||||
|
||||
**参数:**
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| language | string | 否 | 语言代码,默认 'zh-CN' |
|
||||
| continuous | boolean | 否 | 是否连续识别 |
|
||||
| interimResults | boolean | 否 | 是否返回中间结果 |
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
const recognition = glasses.voice.startRecognition({
|
||||
language: 'zh-CN',
|
||||
continuous: true
|
||||
})
|
||||
|
||||
recognition.on('result', (text) => {
|
||||
console.log('识别结果:', text)
|
||||
})
|
||||
```
|
||||
|
||||
### stopRecognition()
|
||||
|
||||
停止语音识别。
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
glasses.voice.stopRecognition()
|
||||
```
|
||||
|
||||
### speak(text, options)
|
||||
|
||||
语音合成。
|
||||
|
||||
**参数:**
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| text | string | 是 | 要合成的文本 |
|
||||
| language | string | 否 | 语言代码 |
|
||||
| speed | number | 否 | 语速,0.5-2.0 |
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
await glasses.voice.speak('Hello World', {
|
||||
language: 'en-US',
|
||||
speed: 1.0
|
||||
})
|
||||
```
|
||||
|
||||
## 传感器 API
|
||||
|
||||
获取传感器数据。
|
||||
|
||||
### getAccelerometer(callback)
|
||||
|
||||
获取加速度数据。
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
glasses.sensors.getAccelerometer((data) => {
|
||||
console.log('加速度:', data.x, data.y, data.z)
|
||||
})
|
||||
```
|
||||
|
||||
### getGyroscope(callback)
|
||||
|
||||
获取陀螺仪数据。
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
glasses.sensors.getGyroscope((data) => {
|
||||
console.log('角速度:', data.x, data.y, data.z)
|
||||
})
|
||||
```
|
||||
|
||||
### getMagnetometer(callback)
|
||||
|
||||
获取磁力计数据。
|
||||
|
||||
**示例:**
|
||||
|
||||
```javascript
|
||||
glasses.sensors.getMagnetometer((data) => {
|
||||
console.log('磁场强度:', data.x, data.y, data.z)
|
||||
})
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user