Compare commits
4 Commits
3401c59c4b
...
bd2c6b95cf
| Author | SHA1 | Date | |
|---|---|---|---|
|
bd2c6b95cf
|
|||
|
0e46bd91d4
|
|||
|
99272b230f
|
|||
|
3c01a76405
|
@@ -4,5 +4,5 @@ uvicorn[standard]
|
||||
whisper_ctranslate2
|
||||
opencc
|
||||
prometheus-fastapi-instrumentator
|
||||
git+https://github.com/SYSTRAN/faster-whisper@be9fb36ed356b9e299b125de6ee91862e0ac9038
|
||||
git+https://github.com/heimoshuiyu/faster-whisper@a759f5f48f5ef5b79461a6461966eafe9df088a9
|
||||
pydub
|
||||
|
||||
@@ -9,7 +9,7 @@ coloredlogs==15.0.1
|
||||
ctranslate2==4.5.0
|
||||
exceptiongroup==1.2.2
|
||||
fastapi==0.115.5
|
||||
faster-whisper @ git+https://github.com/SYSTRAN/faster-whisper@be9fb36ed356b9e299b125de6ee91862e0ac9038
|
||||
faster-whisper @ git+https://github.com/heimoshuiyu/faster-whisper@a759f5f48f5ef5b79461a6461966eafe9df088a9
|
||||
filelock==3.16.1
|
||||
flatbuffers==24.3.25
|
||||
fsspec==2024.10.0
|
||||
@@ -20,15 +20,15 @@ humanfriendly==10.0
|
||||
idna==3.10
|
||||
mpmath==1.3.0
|
||||
numpy==2.1.3
|
||||
onnxruntime==1.20.0
|
||||
onnxruntime==1.20.1
|
||||
OpenCC==1.1.9
|
||||
packaging==24.2
|
||||
prometheus-fastapi-instrumentator==7.0.0
|
||||
prometheus_client==0.21.0
|
||||
protobuf==5.28.3
|
||||
pycparser==2.22
|
||||
pydantic==2.9.2
|
||||
pydantic_core==2.23.4
|
||||
pydantic==2.10.1
|
||||
pydantic_core==2.27.1
|
||||
pydub==0.25.1
|
||||
python-dotenv==1.0.1
|
||||
python-multipart==0.0.17
|
||||
@@ -36,14 +36,14 @@ PyYAML==6.0.2
|
||||
requests==2.32.3
|
||||
sniffio==1.3.1
|
||||
sounddevice==0.5.1
|
||||
starlette==0.41.2
|
||||
starlette==0.41.3
|
||||
sympy==1.13.3
|
||||
tokenizers==0.20.3
|
||||
tqdm==4.67.0
|
||||
typing_extensions==4.12.2
|
||||
urllib3==2.2.3
|
||||
uvicorn==0.32.0
|
||||
uvicorn==0.32.1
|
||||
uvloop==0.21.0
|
||||
watchfiles==0.24.0
|
||||
websockets==14.1
|
||||
whisper-ctranslate2==0.4.7
|
||||
whisper-ctranslate2==0.4.8
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import sys
|
||||
import dataclasses
|
||||
import faster_whisper
|
||||
import tqdm
|
||||
import json
|
||||
from fastapi.responses import StreamingResponse
|
||||
import wave
|
||||
@@ -21,12 +21,16 @@ from fastapi import (
|
||||
WebSocket,
|
||||
)
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from src.whisper_ctranslate2.whisper_ctranslate2 import Transcribe
|
||||
from src.whisper_ctranslate2.writers import format_timestamp
|
||||
from faster_whisper.transcribe import Segment, TranscriptionInfo
|
||||
import opencc
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
|
||||
# redirect print to stderr
|
||||
_print = print
|
||||
def print(*args, **kwargs):
|
||||
_print(*args, file=sys.stderr, **kwargs)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--host", default="0.0.0.0", type=str)
|
||||
parser.add_argument("--port", default=5000, type=int)
|
||||
@@ -95,7 +99,7 @@ def srt_writer(generator: Generator[Segment, Any, None]):
|
||||
|
||||
def vtt_writer(generator: Generator[Segment, Any, None]):
|
||||
yield "WEBVTT\n\n"
|
||||
for i, segment in enumerate(generator):
|
||||
for _, segment in enumerate(generator):
|
||||
start_time = format_timestamp(segment.start)
|
||||
end_time = format_timestamp(segment.end)
|
||||
text = segment.text.strip()
|
||||
@@ -107,15 +111,16 @@ class JsonResult(TranscriptionInfo):
|
||||
segments: list[Segment]
|
||||
text: str
|
||||
|
||||
|
||||
def build_json_result(
|
||||
generator: Iterable[Segment],
|
||||
info: TranscriptionInfo,
|
||||
info: TranscriptionInfo,
|
||||
) -> JsonResult:
|
||||
segments = [i for i in generator]
|
||||
return JsonResult(
|
||||
text="\n".join(i.text for i in segments),
|
||||
segments=segments,
|
||||
**dataclasses.asdict(info)
|
||||
**dataclasses.asdict(info),
|
||||
)
|
||||
|
||||
|
||||
@@ -140,14 +145,12 @@ def stream_builder(
|
||||
"Detected language '%s' with probability %f"
|
||||
% (info.language, info.language_probability)
|
||||
)
|
||||
|
||||
def wrap():
|
||||
last_pos = 0
|
||||
with tqdm.tqdm(total=info.duration, unit="seconds", disable=True) as pbar:
|
||||
for segment in segments:
|
||||
start, end, text = segment.start, segment.end, segment.text
|
||||
pbar.update(end - last_pos)
|
||||
last_pos = end
|
||||
yield segment
|
||||
for segment in segments:
|
||||
if info.language == "zh":
|
||||
segment.text = ccc.convert(segment.text)
|
||||
yield segment
|
||||
|
||||
return wrap(), info
|
||||
|
||||
@@ -303,9 +306,9 @@ async def transcription(
|
||||
"""
|
||||
|
||||
if not task:
|
||||
if request.url.path == '/v1/audio/transcriptions':
|
||||
if request.url.path == "/v1/audio/transcriptions":
|
||||
task = "transcribe"
|
||||
elif request.url.path == '/v1/audio/translations':
|
||||
elif request.url.path == "/v1/audio/translations":
|
||||
task = "translate"
|
||||
else:
|
||||
raise HTTPException(400, "task parameter is required")
|
||||
|
||||
Reference in New Issue
Block a user