feat: add mouth open and close
This commit is contained in:
parent
04fcd79512
commit
8f4a114eaa
@ -7,6 +7,7 @@ annotated-types==0.7.0
|
||||
anyio==3.7.1
|
||||
asttokens==3.0.0
|
||||
attrs==25.1.0
|
||||
blinker==1.9.0
|
||||
certifi==2025.1.31
|
||||
cffi==1.17.1
|
||||
charset-normalizer==3.4.1
|
||||
@ -20,14 +21,18 @@ etelemetry==0.3.1
|
||||
executing==2.2.0
|
||||
filelock==3.17.0
|
||||
fitz==0.0.1.dev2
|
||||
Flask==2.2.3
|
||||
Flask==3.1.0
|
||||
Flask-Cors==3.0.10
|
||||
frontend==0.0.3
|
||||
frozenlist==1.5.0
|
||||
h11==0.14.0
|
||||
h2==4.2.0
|
||||
hpack==4.1.0
|
||||
httpcore==1.0.7
|
||||
httplib2==0.22.0
|
||||
httpx==0.28.1
|
||||
Hypercorn==0.17.3
|
||||
hyperframe==6.1.0
|
||||
idna==3.10
|
||||
ipython==9.0.2
|
||||
ipython_pygments_lexers==1.1.1
|
||||
@ -52,6 +57,7 @@ parso==0.8.4
|
||||
pathlib==1.0.1
|
||||
pexpect==4.9.0
|
||||
pip==25.0
|
||||
priority==2.0.0
|
||||
prompt_toolkit==3.0.50
|
||||
propcache==0.3.0
|
||||
prov==2.0.1
|
||||
@ -70,6 +76,8 @@ python-dotenv==1.0.0
|
||||
pytils==0.4.1
|
||||
pytz==2025.1
|
||||
pyxnat==1.6.3
|
||||
Quart==0.20.0
|
||||
quart-cors==0.8.0
|
||||
rdflib==6.3.2
|
||||
requests==2.28.2
|
||||
scipy==1.15.2
|
||||
@ -90,6 +98,7 @@ urllib3==1.26.20
|
||||
uvicorn==0.34.0
|
||||
wcwidth==0.2.13
|
||||
websockets==10.4
|
||||
Werkzeug==2.2.3
|
||||
Werkzeug==3.1.3
|
||||
wheel==0.45.1
|
||||
wsproto==1.2.0
|
||||
yarl==1.18.3
|
||||
|
||||
32
server.py
32
server.py
@ -3,8 +3,8 @@ import json
|
||||
import logging
|
||||
import requests
|
||||
import base64
|
||||
from flask import Flask, request, jsonify, send_from_directory
|
||||
from flask_cors import CORS
|
||||
from quart import Quart, request, jsonify, send_from_directory
|
||||
from quart_cors import cors
|
||||
import openai
|
||||
import asyncio
|
||||
import aiohttp
|
||||
@ -48,8 +48,8 @@ except Exception as e:
|
||||
logger.error(f"Error loading settings: {e}")
|
||||
port = 6006
|
||||
|
||||
app = Flask(__name__, static_url_path='')
|
||||
CORS(app)
|
||||
app = Quart(__name__, static_url_path='')
|
||||
cors(app)
|
||||
|
||||
# 存储当前加载的PDF路径
|
||||
current_pdf_path = None
|
||||
@ -212,8 +212,8 @@ def serve_static(path):
|
||||
return send_from_directory('', path)
|
||||
|
||||
@app.route('/api/explain', methods=['POST'])
|
||||
def explain():
|
||||
data = request.json
|
||||
async def explain():
|
||||
data = await request.json
|
||||
text = data.get('text', '')
|
||||
page_num = data.get('page', None)
|
||||
|
||||
@ -235,8 +235,8 @@ def explain():
|
||||
})
|
||||
|
||||
@app.route('/api/tts', methods=['POST'])
|
||||
def tts():
|
||||
data = request.json
|
||||
async def tts():
|
||||
data = await request.json
|
||||
text = data.get('text', '')
|
||||
voice = data.get('voice', 'zf_xiaoxiao')
|
||||
speed = data.get('speed', 1.0)
|
||||
@ -272,6 +272,7 @@ async def generate_cache_explanation(page_num,voice,speed):
|
||||
result.append(generate_explanation(page_num, text))
|
||||
result.append(await text_to_speech(result[0], voice, speed))
|
||||
cache_explanation[page_num] = result
|
||||
logger.info(f"已缓存讲解: {page_num}")
|
||||
|
||||
if page_num+1 not in cache_explanation and page_num+1 > 0 and page_num+1 <= pdfpages:
|
||||
text = extract_page_text(current_pdf_path, page_num+1)["page_text"]
|
||||
@ -279,6 +280,7 @@ async def generate_cache_explanation(page_num,voice,speed):
|
||||
result.append(generate_explanation(page_num+1, text))
|
||||
result.append(await text_to_speech(result[0], voice, speed))
|
||||
cache_explanation[page_num+1] = result
|
||||
logger.info(f"已缓存讲解: {page_num+1}")
|
||||
|
||||
if page_num-1 not in cache_explanation and page_num-1 > 0 and page_num-1 <= pdfpages:
|
||||
text = extract_page_text(current_pdf_path, page_num-1)["page_text"]
|
||||
@ -286,19 +288,20 @@ async def generate_cache_explanation(page_num,voice,speed):
|
||||
result.append(generate_explanation(page_num-1, text))
|
||||
result.append(await text_to_speech(result[0], voice, speed))
|
||||
cache_explanation[page_num-1] = result
|
||||
logger.info(f"已缓存讲解: {page_num-1}")
|
||||
|
||||
|
||||
|
||||
@app.route('/api/explain_with_audio', methods=['POST'])
|
||||
def explain_with_audio():
|
||||
async def explain_with_audio():
|
||||
global cache_explanation
|
||||
data = request.json
|
||||
data = await request.json
|
||||
text = data.get('text', '')
|
||||
page_num = data.get('page', None)
|
||||
voice = data.get('voice', 'zf_xiaoxiao')
|
||||
speed = data.get('speed', 1.0)
|
||||
# 这里多线程执行, 用于提前加载缓存的讲解
|
||||
generate_cache_explanation(page_num,voice,speed)
|
||||
asyncio.create_task(generate_cache_explanation(page_num,voice,speed))
|
||||
# 如果已经有缓存的讲解,直接返回
|
||||
if page_num in cache_explanation:
|
||||
explanation = cache_explanation[page_num][0]
|
||||
@ -345,14 +348,15 @@ def explain_with_audio():
|
||||
})
|
||||
|
||||
@app.route('/api/load_pdf', methods=['POST'])
|
||||
def load_pdf():
|
||||
async def load_pdf():
|
||||
global current_pdf_path
|
||||
global cache_explanation
|
||||
global pdfpages
|
||||
# 清空cache
|
||||
cache_explanation = {}
|
||||
|
||||
data = request.json
|
||||
data = await request.json
|
||||
logger.info(f"加载PDF: {data}")
|
||||
pdf_path = data.get('path', './public/pdf/test.pdf')
|
||||
|
||||
|
||||
@ -377,7 +381,7 @@ def load_pdf():
|
||||
voice = 'zf_xiaoxiao'
|
||||
speed = 1.0
|
||||
start_time = time.time()
|
||||
asyncio.run(generate_cache_explanation(1,voice,speed))
|
||||
await generate_cache_explanation(0,voice,speed)
|
||||
logger.info(f"预加载讲解耗时: {time.time()-start_time}")
|
||||
return jsonify({
|
||||
'success': True,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user