mirror of
https://github.com/w-okada/voice-changer.git
synced 2025-02-02 16:23:58 +03:00
update
This commit is contained in:
parent
9b27da7f6e
commit
059962c9cb
@ -1,17 +1,17 @@
|
|||||||
from flask import Flask, request, Markup, abort, jsonify, send_from_directory
|
import uvicorn
|
||||||
from flask_cors import CORS
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from fastapi.encoders import jsonable_encoder
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from logging.config import dictConfig
|
import os, sys, base64, traceback, struct
|
||||||
import sys
|
|
||||||
import base64
|
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy.io.wavfile import write, read
|
from scipy.io.wavfile import write, read
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
import traceback
|
|
||||||
import struct
|
|
||||||
|
|
||||||
sys.path.append("mod")
|
sys.path.append("mod")
|
||||||
sys.path.append("mod/text")
|
sys.path.append("mod/text")
|
||||||
@ -21,32 +21,6 @@ from data_utils import TextAudioSpeakerLoader, TextAudioSpeakerCollate
|
|||||||
from models import SynthesizerTrn
|
from models import SynthesizerTrn
|
||||||
from text.symbols import symbols
|
from text.symbols import symbols
|
||||||
|
|
||||||
dictConfig({
|
|
||||||
'version': 1,
|
|
||||||
'formatters': {'default': {
|
|
||||||
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
|
|
||||||
}},
|
|
||||||
'handlers': {'wsgi': {
|
|
||||||
'class': 'logging.StreamHandler',
|
|
||||||
'stream': 'ext://flask.logging.wsgi_errors_stream',
|
|
||||||
'formatter': 'default'
|
|
||||||
}},
|
|
||||||
'root': {
|
|
||||||
'level': 'INFO',
|
|
||||||
'handlers': ['wsgi']
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
@app.route("/<path:path>")
|
|
||||||
def static_dir(path):
|
|
||||||
return send_from_directory("../frontend/dist", path)
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET'])
|
|
||||||
def redirect_to_index():
|
|
||||||
return send_from_directory("../frontend/dist", 'index.html')
|
|
||||||
|
|
||||||
CORS(app, resources={r"/*": {"origins": "*"}})
|
|
||||||
|
|
||||||
class VoiceChanger():
|
class VoiceChanger():
|
||||||
def __init__(self, config, model):
|
def __init__(self, config, model):
|
||||||
@ -96,26 +70,60 @@ class VoiceChanger():
|
|||||||
return audio1
|
return audio1
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger('uvicorn')
|
||||||
|
|
||||||
@app.route('/test', methods=['GET', 'POST'])
|
args = sys.argv
|
||||||
def test():
|
PORT = args[1]
|
||||||
|
CONFIG = args[2]
|
||||||
|
MODEL = args[3]
|
||||||
|
logger.info('INITIALIZE MODEL')
|
||||||
|
voiceChanger = VoiceChanger(CONFIG, MODEL)
|
||||||
|
voiceChanger.on_request(0,0,0,0,0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=["*"],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
|
app.mount("/front", StaticFiles(directory="../frontend/dist", html=True), name="static")
|
||||||
|
|
||||||
|
@app.get("/test")
|
||||||
|
def get_test():
|
||||||
try:
|
try:
|
||||||
if request.method == 'GET':
|
|
||||||
return request.args.get('query', '')
|
return request.args.get('query', '')
|
||||||
elif request.method == 'POST':
|
except Exception as e:
|
||||||
|
print("REQUEST PROCESSING!!!! EXCEPTION!!!", e)
|
||||||
|
print(traceback.format_exc())
|
||||||
|
return str(e)
|
||||||
|
|
||||||
|
class VoiceModel(BaseModel):
|
||||||
|
gpu: int
|
||||||
|
srcId: int
|
||||||
|
dstId: int
|
||||||
|
timestamp: int
|
||||||
|
buffer: str
|
||||||
|
|
||||||
|
@app.post("/test")
|
||||||
|
def post_test(voice:VoiceModel):
|
||||||
|
global voiceChanger
|
||||||
|
try:
|
||||||
print("POST REQUEST PROCESSING....")
|
print("POST REQUEST PROCESSING....")
|
||||||
gpu = int(request.json['gpu'])
|
gpu = voice.gpu
|
||||||
srcId = int(request.json['srcId'])
|
srcId = voice.srcId
|
||||||
dstId = int(request.json['dstId'])
|
dstId = voice.dstId
|
||||||
timestamp = int(request.json['timestamp'])
|
timestamp = voice.timestamp
|
||||||
buffer = request.json['buffer']
|
buffer = voice.buffer
|
||||||
wav = base64.b64decode(buffer)
|
wav = base64.b64decode(buffer)
|
||||||
# print(wav)
|
|
||||||
# print(base64.b64encode(wav))
|
|
||||||
changedVoice = voiceChanger.on_request(gpu, srcId, dstId, timestamp, wav)
|
changedVoice = voiceChanger.on_request(gpu, srcId, dstId, timestamp, wav)
|
||||||
changedVoiceBase64 = base64.b64encode(changedVoice).decode('utf-8')
|
changedVoiceBase64 = base64.b64encode(changedVoice).decode('utf-8')
|
||||||
# print("changedVoice",changedVoice)
|
|
||||||
# print("CV64",changedVoiceBase64)
|
|
||||||
data = {
|
data = {
|
||||||
"gpu":gpu,
|
"gpu":gpu,
|
||||||
"srcId":srcId,
|
"srcId":srcId,
|
||||||
@ -123,22 +131,15 @@ def test():
|
|||||||
"timestamp":timestamp,
|
"timestamp":timestamp,
|
||||||
"changedVoiceBase64":changedVoiceBase64
|
"changedVoiceBase64":changedVoiceBase64
|
||||||
}
|
}
|
||||||
return jsonify(data)
|
|
||||||
else:
|
json_compatible_item_data = jsonable_encoder(data)
|
||||||
return abort(400)
|
|
||||||
|
return JSONResponse(content=json_compatible_item_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("REQUEST PROCESSING!!!! EXCEPTION!!!", e)
|
print("REQUEST PROCESSING!!!! EXCEPTION!!!", e)
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
return str(e)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = sys.argv
|
logger.info('START APP')
|
||||||
PORT = args[1]
|
uvicorn.run(f"{os.path.basename(__file__)[:-3]}:app", host="0.0.0.0", port=int(PORT), reload=True)
|
||||||
CONFIG = args[2]
|
|
||||||
MODEL = args[3]
|
|
||||||
app.logger.info('INITIALIZE MODEL')
|
|
||||||
voiceChanger = VoiceChanger(CONFIG, MODEL)
|
|
||||||
voiceChanger.on_request(0,0,0,0,0)
|
|
||||||
app.logger.info('START APP')
|
|
||||||
app.run(debug=True, host='0.0.0.0',port=PORT)
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM dannadori/voice-changer-internal:20220919_045352 as front
|
FROM dannadori/voice-changer-internal:20220919_060759 as front
|
||||||
FROM debian:bullseye-slim as base
|
FROM debian:bullseye-slim as base
|
||||||
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
Loading…
Reference in New Issue
Block a user