-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9414423
commit c14a864
Showing
144 changed files
with
52,653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 hawkey | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
## 消息格式 | ||
|
||
通讯地址:`ws://127.0.0.1:8800/th` | ||
|
||
### 发送音频 | ||
|
||
``` | ||
# 发送给api的message数据是str类型 | ||
{ | ||
"Topic": "Unreal", | ||
"Data": { | ||
"Key": "audio", | ||
"Value": "C:\samples\sample-1.mp3", | ||
"Time": 10, | ||
"Type": "interact" | ||
} | ||
} | ||
``` | ||
|
||
| 参数 | 描述 | 类型 | 是否必须 | | ||
| ---------- | ---------------- | ----- | -------- | | ||
| Data.Value | 音频文件绝对路径 | str | 是 | | ||
| Data.Time | 音频时长 (秒) | float | 否 | | ||
| Data.Type | 发言类型 | str | 否 | | ||
|
||
接口测试场景:Postman | ||
|
||
 | ||
|
||
### 返回视频 | ||
|
||
```json | ||
# 返回数据的格式,Json | ||
{ | ||
'video': 'data:video/mp4;base64,xxx' | ||
} | ||
``` | ||
|
||
| 参数 | 描述 | 类型 | 是否必须 | | ||
| ----- | ---------------------------------------------------------- | ---- | -------- | | ||
| video | base64编码的视频流,前段接收时需要采用base64对视频进行解码 | str | 是 | | ||
| | | | | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import torch | ||
from torch.autograd import Function | ||
from torch.cuda.amp import custom_bwd, custom_fwd | ||
|
||
class _trunc_exp(Function): | ||
@staticmethod | ||
@custom_fwd(cast_inputs=torch.float32) # cast to float32 | ||
def forward(ctx, x): | ||
ctx.save_for_backward(x) | ||
return torch.exp(x) | ||
|
||
@staticmethod | ||
@custom_bwd | ||
def backward(ctx, g): | ||
x = ctx.saved_tensors[0] | ||
return g * torch.exp(x.clamp(-15, 15)) | ||
|
||
trunc_exp = _trunc_exp.apply |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# server.py | ||
from flask import Flask, request, jsonify | ||
from flask_sockets import Sockets | ||
import base64 | ||
import time | ||
import json | ||
import gevent | ||
from gevent import pywsgi | ||
from geventwebsocket.handler import WebSocketHandler | ||
from tools import audio_pre_process, video_pre_process, generate_video,audio_process | ||
import os | ||
import re | ||
import numpy as np | ||
|
||
import shutil | ||
app = Flask(__name__) | ||
sockets = Sockets(app) | ||
video_list = [] | ||
|
||
|
||
|
||
|
||
|
||
def send_information(path, ws): | ||
|
||
print('传输信息开始!') | ||
#path = video_list[0] | ||
'''''' | ||
with open(path, 'rb') as f: | ||
video_data = base64.b64encode(f.read()).decode() | ||
|
||
data = { | ||
'video': 'data:video/mp4;base64,%s' % video_data, | ||
} | ||
json_data = json.dumps(data) | ||
|
||
ws.send(json_data) | ||
|
||
|
||
|
||
@sockets.route('/th') | ||
def echo_socket(ws): | ||
# 获取WebSocket对象 | ||
#ws = request.environ.get('wsgi.websocket') | ||
# 如果没有获取到,返回错误信息 | ||
if not ws: | ||
print('未建立连接!') | ||
return 'Please use WebSocket' | ||
# 否则,循环接收和发送消息 | ||
else: | ||
print('建立连接!') | ||
while True: | ||
message = ws.receive() | ||
|
||
|
||
|
||
|
||
if len(message)==0: | ||
|
||
return '输入信息为空' | ||
else: | ||
|
||
message=message.replace("\\","/") | ||
print('message:', message,type(message)) | ||
message = eval(message) | ||
aud_dir = message["Data"]["Value"] | ||
basedir = "" | ||
for i in aud_dir.split("/"): | ||
basedir = os.path.join(basedir,i) | ||
basedir = basedir.replace(":",":\\") | ||
num = 1 | ||
new_path = r'./data/audio/aud_%d.wav'%num #新路径 | ||
old_path = basedir | ||
shutil.copy(old_path, new_path) | ||
audio_path = 'data/audio/aud_%d.wav' % num | ||
audio_process(audio_path) | ||
audio_path_eo = 'data/audio/aud_%d_eo.npy' % num | ||
video_path = 'data/video/results/ngp_%d.mp4' % num | ||
output_path = 'data/video/results/output_%d.mp4' % num | ||
generate_video(audio_path, audio_path_eo, video_path, output_path) | ||
video_list.append(output_path) | ||
send_information(output_path, ws) | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
|
||
audio_pre_process() | ||
video_pre_process() | ||
|
||
server = pywsgi.WSGIServer(('127.0.0.1', 8800), app, handler_class=WebSocketHandler) | ||
server.serve_forever() | ||
|
||
|
Binary file not shown.
Binary file not shown.
Oops, something went wrong.