feat: openvoice重构,添加语音克隆功能
This commit is contained in:
1 parent
8369090313
commit
5cf16bf03b
6 files changed
+99
-32
No files matched your search
Binary file not shown.
@@ -30,6 +30,7 @@ class ChatServiceTest:
|
||||
}
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
if response.status_code == 200:
|
||||
print("用户创建成功")
|
||||
self.user_id = response.json()['data']['user_id']
|
||||
else:
|
||||
raise Exception("创建聊天时,用户创建失败")
|
||||
@@ -57,6 +58,21 @@ class ChatServiceTest:
|
||||
else:
|
||||
raise Exception("创建聊天时,角色创建失败")
|
||||
|
||||
#上传音频用于音频克隆
|
||||
url = f"{self.socket}/users/audio?user_id={self.user_id}"
|
||||
current_file_path = os.path.abspath(__file__)
|
||||
current_file_path = os.path.dirname(current_file_path)
|
||||
tests_dir = os.path.dirname(current_file_path)
|
||||
mp3_file_path = os.path.join(tests_dir, 'assets', 'demo_speaker0.mp3')
|
||||
with open(mp3_file_path, 'rb') as audio_file:
|
||||
files = {'audio_file':(mp3_file_path, audio_file, 'audio/mpeg')}
|
||||
response = requests.post(url,files=files)
|
||||
if response.status_code == 200:
|
||||
self.audio_id = response.json()['data']['audio_id']
|
||||
print("音频上传成功")
|
||||
else:
|
||||
raise Exception("音频上传失败")
|
||||
|
||||
#创建一个对话
|
||||
url = f"{self.socket}/chats"
|
||||
payload = json.dumps({
|
||||
@@ -66,6 +82,7 @@ class ChatServiceTest:
|
||||
headers = {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
if response.status_code == 200:
|
||||
print("对话创建成功")
|
||||
@@ -302,6 +319,11 @@ class ChatServiceTest:
|
||||
else:
|
||||
raise Exception("聊天删除测试失败")
|
||||
|
||||
url = f"{self.socket}/users/audio/{self.audio_id}"
|
||||
response = requests.request("DELETE", url)
|
||||
if response.status_code != 200:
|
||||
raise Exception("音频删除测试失败")
|
||||
|
||||
url = f"{self.socket}/users/{self.user_id}"
|
||||
response = requests.request("DELETE", url)
|
||||
if response.status_code != 200:
|
||||
@@ -312,7 +334,6 @@ class ChatServiceTest:
|
||||
if response.status_code != 200:
|
||||
raise Exception("角色删除测试失败")
|
||||
|
||||
|
||||
def chat_test():
|
||||
chat_service_test = ChatServiceTest()
|
||||
chat_service_test.test_create_chat()
|
||||
|
||||
@@ -5,7 +5,7 @@ import os
|
||||
|
||||
|
||||
class UserServiceTest:
|
||||
def __init__(self,socket="http://127.0.0.1:8001"):
|
||||
def __init__(self,socket="http://127.0.0.1:7878"):
|
||||
self.socket = socket
|
||||
|
||||
def test_user_create(self):
|
||||
@@ -132,7 +132,7 @@ class UserServiceTest:
|
||||
current_file_path = os.path.abspath(__file__)
|
||||
current_dir = os.path.dirname(current_file_path)
|
||||
tests_dir = os.path.dirname(current_dir)
|
||||
wav_file_path = os.path.join(tests_dir, 'assets', 'iat_mp3_8k.mp3')
|
||||
wav_file_path = os.path.join(tests_dir, 'assets', 'demo_speaker0.mp3')
|
||||
with open(wav_file_path, 'rb') as audio_file:
|
||||
files = {'audio_file':(wav_file_path,audio_file,'audio/mpeg')}
|
||||
response = requests.post(url, files=files)
|
||||
@@ -141,15 +141,15 @@ class UserServiceTest:
|
||||
print("音频上传测试成功")
|
||||
else:
|
||||
raise Exception("音频上传测试失败")
|
||||
|
||||
|
||||
def test_update_audio(self):
|
||||
url = f"{self.socket}/users/audio/{self.audio_id}"
|
||||
current_file_path = os.path.abspath(__file__)
|
||||
current_dir = os.path.dirname(current_file_path)
|
||||
tests_dir = os.path.dirname(current_dir)
|
||||
wav_file_path = os.path.join(tests_dir, 'assets', 'iat_mp3_8k.mp3')
|
||||
wav_file_path = os.path.join(tests_dir, 'assets', 'demo_speaker0.mp3')
|
||||
with open(wav_file_path, 'rb') as audio_file:
|
||||
files = {'audio_file':(wav_file_path,audio_file,'audio/mpeg')}
|
||||
files = {'audio_file':(wav_file_path,audio_file,'audio/wav')}
|
||||
response = requests.put(url, files=files)
|
||||
if response.status_code == 200:
|
||||
print("音频上传测试成功")
|
||||
|
||||
Reference in new issue
Block a user