

no online conflict when multiple users
@9faf3da8d3032b8afd0cc3dbd409703b96c72bdb
--- whisper_fastapi_online_server.py
+++ whisper_fastapi_online_server.py
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 |
from fastapi.responses import HTMLResponse |
10 | 10 |
from fastapi.middleware.cors import CORSMiddleware |
11 | 11 |
|
12 |
-from whisper_online import asr_factory, add_shared_args |
|
12 |
+from whisper_online import backend_factory, online_factory, add_shared_args |
|
13 | 13 |
|
14 | 14 |
app = FastAPI() |
15 | 15 |
app.add_middleware( |
... | ... | @@ -40,7 +40,7 @@ |
40 | 40 |
add_shared_args(parser) |
41 | 41 |
args = parser.parse_args() |
42 | 42 |
|
43 |
-asr, online = asr_factory(args) |
|
43 |
+asr, tokenizer = backend_factory(args) |
|
44 | 44 |
|
45 | 45 |
# Load demo HTML for the root endpoint |
46 | 46 |
with open("src/live_transcription.html", "r") as f: |
... | ... | @@ -85,6 +85,9 @@ |
85 | 85 |
|
86 | 86 |
ffmpeg_process = await start_ffmpeg_decoder() |
87 | 87 |
pcm_buffer = bytearray() |
88 |
+ print("Loading online.") |
|
89 |
+ online = online_factory(args, asr, tokenizer) |
|
90 |
+ print("Online loaded.") |
|
88 | 91 |
|
89 | 92 |
# Continuously read decoded PCM from ffmpeg stdout in a background task |
90 | 93 |
async def ffmpeg_stdout_reader(): |
--- whisper_online.py
+++ whisper_online.py
... | ... | @@ -920,11 +920,7 @@ |
920 | 920 |
default="DEBUG", |
921 | 921 |
) |
922 | 922 |
|
923 |
- |
|
924 |
-def asr_factory(args, logfile=sys.stderr): |
|
925 |
- """ |
|
926 |
- Creates and configures an ASR and ASR Online instance based on the specified backend and arguments. |
|
927 |
- """ |
|
923 |
+def backend_factory(args): |
|
928 | 924 |
backend = args.backend |
929 | 925 |
if backend == "openai-api": |
930 | 926 |
logger.debug("Using OpenAI API.") |
... | ... | @@ -967,10 +963,10 @@ |
967 | 963 |
tokenizer = create_tokenizer(tgt_language) |
968 | 964 |
else: |
969 | 965 |
tokenizer = None |
966 |
+ return asr, tokenizer |
|
970 | 967 |
|
971 |
- # Create the OnlineASRProcessor |
|
968 |
+def online_factory(args, asr, tokenizer, logfile=sys.stderr): |
|
972 | 969 |
if args.vac: |
973 |
- |
|
974 | 970 |
online = VACOnlineASRProcessor( |
975 | 971 |
args.min_chunk_size, |
976 | 972 |
asr, |
... | ... | @@ -985,9 +981,15 @@ |
985 | 981 |
logfile=logfile, |
986 | 982 |
buffer_trimming=(args.buffer_trimming, args.buffer_trimming_sec), |
987 | 983 |
) |
988 |
- |
|
984 |
+ return online |
|
985 |
+ |
|
986 |
+def asr_factory(args, logfile=sys.stderr): |
|
987 |
+ """ |
|
988 |
+ Creates and configures an ASR and ASR Online instance based on the specified backend and arguments. |
|
989 |
+ """ |
|
990 |
+ asr, tokenizer = backend_factory(args) |
|
991 |
+ online = online_factory(args, asr, tokenizer, logfile=logfile) |
|
989 | 992 |
return asr, online |
990 |
- |
|
991 | 993 |
|
992 | 994 |
def set_logging(args, logger, other="_server"): |
993 | 995 |
logging.basicConfig(format="%(levelname)s\t%(message)s") # format='%(name)s |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?