Skip to content

Commit

Permalink
fix: api cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed Jul 7, 2024
1 parent 70bf4df commit cef8b6e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION=1
version_str="v0.0.1"
VERSION=2
version_str="v0.0.2"
7 changes: 6 additions & 1 deletion lib/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ def parse_ini():
t = line.strip()
if t and not t.startswith(';') and t.find('=') > 0:
t = t.split('=', maxsplit=1)
sets[t[0]] = t[1]
if t[1]=='false':
sets[t[0]]=False
elif t[1]=='true':
sets[t[0]]=True
else:
sets[t[0]] = t[1] if t[1] else ""

return sets

Expand Down
3 changes: 2 additions & 1 deletion set.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
;绑定ip和端口, 127.0.0.1 代表本机,9933为端口
web_address=127.0.0.1:9933
web_address=127.0.0.1:9933
only_local=false
8 changes: 5 additions & 3 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask import Flask, request, render_template, jsonify, send_from_directory
import os
import logging
import time
from logging.handlers import RotatingFileHandler
import warnings

Expand Down Expand Up @@ -58,7 +59,7 @@ def api():
noextname, ext = os.path.splitext(audio_file.filename)
ext = ext.lower()
# 如果是视频,先分离
wav_file = os.path.join(cfg.TMP_DIR, f'{noextname}.wav')
wav_file = os.path.join(cfg.TMP_DIR, f'{time.time()}.wav')
print(f'{wav_file=}')
if not os.path.exists(wav_file) or os.path.getsize(wav_file) == 0:
if ext in ['.mp4', '.mov', '.avi', '.mkv', '.mpeg', '.mp3', '.flac']:
Expand All @@ -78,17 +79,18 @@ def api():
audio_file.save(wav_file)
else:
return jsonify({"code": 1, "msg": f"不支持的格式 {ext}"})
print(f'{ext=}')
#print(f'{ext=}')
sets = cfg.parse_ini()
model = AutoModel(model="paraformer-zh", model_revision="v2.0.4",
vad_model="fsmn-vad", vad_model_revision="v2.0.4",
punc_model="ct-punc-c", punc_model_revision="v2.0.4",
local_files_only=cfg.sets.get('only_local',False)
)
res = model.generate(input=wav_file, return_raw_text=True, is_final=True,
sentence_timestamp=True, batch_size_s=100)
raw_subtitles = []
for it in res[0]['sentence_info']:
print(it)
#print(it)
raw_subtitles.append({
"line": len(raw_subtitles) + 1,
"text": it['text'],
Expand Down
Binary file added static/layui.zip
Binary file not shown.

0 comments on commit cef8b6e

Please sign in to comment.