docs: add chunk API usage, playback format, and API examples

This commit is contained in:
Warren
2026-03-25 16:06:11 +08:00
parent f8925ab994
commit 17cab667f9
3 changed files with 231 additions and 41 deletions

View File

@@ -154,10 +154,54 @@ curl -s -X POST "https://api.momentry.ddns.net/api/v1/search" \
-H "Content-Type: application/json" \
-d '{
"query": "測試關鍵字",
"top_k": 5
"limit": 5
}'
```
### 取得分段Chunk內容
搜尋結果會返回影片分段Chunk包含可播放的時間軸資訊
```json
{
"results": [
{
"uuid": "39567a0eb16f39fd",
"chunk_id": "sentence_1471",
"chunk_type": "sentence",
"start_time": 5309.08,
"end_time": 5311.08,
"text": "influenced by a vital way,",
"score": 0.68
}
]
}
```
**Chunk 欄位說明**:
| 欄位 | 說明 |
|------|------|
| `uuid` | 影片 UUID用於取得影片網址 |
| `chunk_id` | 分段 ID |
| `chunk_type` | 分段類型sentence/cut/time/trace/story |
| `start_time` | 開始時間(秒) |
| `end_time` | 結束時間(秒) |
| `text` | 語音內容文字 |
| `score` | 相似度分數0-1 |
### 播放分段
取得 Chunk 後可組合成播放網址:
```
影片網址?start={start_time}&end={end_time}
```
範例:
```
https://wp.momentry.ddns.net/video.mp4?start=5309.08&end=5311.08
```
---
## 完整 n8n Workflow 範例
@@ -295,7 +339,7 @@ switch ($job['status']) {
}
```
### Step 5: 搜尋內容
### Step 5: 搜尋內容並取得 Chunk
```php
<?php
@@ -303,14 +347,18 @@ switch ($job['status']) {
$results = Momentry_API::search('測試關鍵字', 5);
foreach ($results['results'] as $result) {
echo "UUID: " . $result['chunk_id'] . "\n";
echo "分數: " . $result['score'] . "\n";
echo "影片 UUID: " . $result['uuid'] . "\n";
echo "Chunk ID: " . $result['chunk_id'] . "\n";
echo "類型: " . $result['chunk_type'] . "\n";
echo "開始: " . $result['start_time'] . "s\n";
echo "結束: " . $result['end_time'] . "s\n";
echo "內容: " . ($result['text'] ?? '') . "\n";
echo "相似度: " . $result['score'] . "\n";
echo "---\n";
}
```
### WordPress Shortcode 範例
### WordPress Shortcode 範例(可點擊播放)
```php
<?php
@@ -337,10 +385,21 @@ add_shortcode('momentry_search', function($atts) {
$html .= '<ul>';
foreach ($results['results'] as $result) {
$video_uuid = $result['uuid'];
$start = $result['start_time'] ?? 0;
$end = $result['end_time'] ?? 0;
$text = $result['text'] ?? '無文字描述';
$html .= '<li>';
$html .= '<strong>時間: ' . ($result['start_time'] ?? 'N/A') . 's</strong>';
$html .= '<a href="/player?uuid=' . esc_attr($video_uuid) .
'&start=' . esc_attr($start) .
'&end=' . esc_attr($end) . '">';
$html .= '播放 ' . $start . 's - ' . $end . 's';
$html .= '</a>';
$html .= '<br>';
$html .= esc_html($result['text'] ?? '無文字描述');
$html .= '<small>相似度: ' . round($result['score'] * 100) . '%</small>';
$html .= '<br>';
$html .= esc_html($text);
$html .= '</li>';
}
@@ -398,3 +457,4 @@ add_shortcode('momentry_search', function($atts) {
| 版本 | 日期 | 內容 | 操作人 |
|------|------|------|--------|
| V1.0 | 2026-03-25 | 初版建立 | OpenCode |
| V1.1 | 2026-03-25 | 新增 Chunk 取得與播放說明、Shortcode 範例 | OpenCode |