fastwhisper/README.md
2025-11-06 15:33:33 +08:00

232 lines
4.2 KiB
Markdown

# fastwhisper
A wraps for [fast-whisper](https://github.com/SYSTRAN/faster-whisper) with following features:
* a web server
* with following API
1 transcribe
sumits a asr task, and return a dict contains 'task_id' which can use to query task status
2 status
inquery a task status, if 'SUCCEEDED', the result of transcribe will carry out
3 asr
sumbit a asr task and wait it success or failed
## Deperndents
fastwhisper will installs all its dependents when install
## Download and Install
use follow command to download fastwhisper
```
git clone https://git.opencomputing.cn/yumoqing/fastwhisper.git
```
go to the folder 'fastwhisper'
```
cd fastwhisper
```
change some config items
```
vi conf/config.json
```
modify the following items
```
"model_path": "/data/ymq/models/deepdml/faster-whisper-large-v3-turbo-ct2",
"redis_url": "redis://127.0.0.1:6379",
"worker_cnt": 1,
"port":9925,
```
finally
```
bash ./build.sh
```
./build.sh will
1 make virtual environment in "py3" folder
2 install all packages it needs
3 use "APT" install redis-server, if not on ubuntu, you need to modify build.sh
4 create a system service named "fastwhisper"
5 start fastwhisper servcie
## APIs
### transcribe
* PATH: /v1/transcribe
* headers we need the following header
```
{
"Content-Type": "application/json"
}
```
* data
```
{
"audio_file": a.wav or b.mp3
"beam_size": default is 5
"temperature": default is 0.0
"word_timestamps": default is True
}
```
* response
```
{
"task_id": "13hewndskj83r3"
}
```
* curl examples
```
curl -X POST http://127.0.0.1:9925/v1/transcribe \
-H "Content-TYpe: application/json" \
-d '{
"audio_file": "1.wav"
}'
```
### status
* path: /v1/status
* params
```
{
"task_id": "task id return from transcribe api"
}
```
* response
```
{
"finished_at": "1762402570.5322073",
"task_id": "23z2tWN6Z7hlqCgvusigZ",
"status": "SUCCEEDED",
"payload": "{\"audio_file\": \"1.wav\"}",
"started_at": "1762402566.946902",
"result": {
"language": "zh",
"language_probability": 0.99755859375,
"segments": [
[
0.0,
29.98,
"优优独播剧场——YoYo Television Series Exclusive"
],
[
123.78,
126.66000000000001,
"产品和研发"
],
......
[
126.66000000000001,
128.22,
"哦"
],
[
128.22,
130.85999999999999,
"一起把未来憧憬"
],
]
},
"created_at": "1762402566.9158587"
}
```
#### response explanation
* status
prosible values are "PENGING":means not starting running, "RUNNING": is running, "FAILED": finished with error, "SUCCEEDED": finished without error
* result
1 'FAILED'
result is the error string
2 'SUCCEEDED'
result is the transcribe result dict
keys in result:
I language
identified language
II language_probability
probability of language
III segments
it is a list of segment
IV segment
start end text
* curl example
```
url http://127.0.0.1:9925/v1/status?task_id=23z2tWN6Z7hlqCgvusigZ
```
### asr
* path: /v1/asr
* headers
we need the following header
```
{
"Content-Type": "application/json"
}
```
* data
```
{
"audio_file": a.wav or b.mp3
}
```
* response
```
{
"finished_at": "1762402570.5322073",
"task_id": "23z2tWN6Z7hlqCgvusigZ",
"status": "SUCCEEDED",
"payload": "{\"audio_file\": \"1.wav\"}",
"started_at": "1762402566.946902",
"result": {
"language": "zh",
"language_probability": 0.99755859375,
"segments": [
[
0.0,
29.98,
"优优独播剧场——YoYo Television Series Exclusive"
],
[
123.78,
126.66000000000001,
"产品和研发"
],
......
[
126.66000000000001,
128.22,
"哦"
],
[
128.22,
130.85999999999999,
"一起把未来憧憬"
],
]
},
"created_at": "1762402566.9158587"
}
```