Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an openai compatible api #60

Merged
merged 2 commits into from
Dec 1, 2023
Merged

add an openai compatible api #60

merged 2 commits into from
Dec 1, 2023

Conversation

lewangdev
Copy link
Contributor

No description provided.

@lewangdev
Copy link
Contributor Author

#42

@syq163
Copy link
Collaborator

syq163 commented Nov 30, 2023

Great job! I'm excited to set up the environment, but I encountered an issue with Python 3.8. Could you please confirm if PR is compatible with Python 3.8, as it's the recommended version to run with EmotiVoice?

@lewangdev
Copy link
Contributor Author

OK,I will test it on Python 3.8.

@lewangdev
Copy link
Contributor Author

Hi,
I configured my development environment using the Docker image syq163/emoti-voice:latest, which has Python version 3.10.12.

I used FastAPI to implement the openai compatible API for emoti-voice. And Python 3.10+ has the best and simplest syntax for type hints.

I will change to Python 3.8+ type hints to run with EmotiVoice.

@syq163
Copy link
Collaborator

syq163 commented Dec 1, 2023

Hi, I configured my development environment using the Docker image syq163/emoti-voice:latest, which has Python version 3.10.12.

I used FastAPI to implement the openai compatible API for emoti-voice. And Python 3.10+ has the best and simplest syntax for type hints.

I will change to Python 3.8+ type hints to run with EmotiVoice.

Thank you for the information. Yeah, I agree 3.10+ might be better.

@syq163
Copy link
Collaborator

syq163 commented Dec 1, 2023

I have tried Python 3.10 and it works fine. I have two suggestions:

  1. I have modified the 'openaiapi.py' file to make it compatible with Python 3.8. Please check it.
    openaiapi.txt

  2. I see that you have modified the 'frontend_cn.py' file to make it more robust. However, I suggest that we keep 'frontend_cn.py' unchanged as errors may help us improve it.
    One more thing, it seems that the 'log-config.yml' file is not that necessary, is that right?

@lewangdev
Copy link
Contributor Author

Great!

it's amazing to see that you have already finished the changes so quickly. I'm sorry that I didn't have time today to modify and support Python 3.8.

log-config.yml is unnecessary and can be deleted.

I agree that you keep 'frontend_cn.py' unchanged.

@syq163
Copy link
Collaborator

syq163 commented Dec 1, 2023

Thank you for confirming that. Could you please make the necessary updates as we discussed, so that I can easily merge the PR?

Great!

it's amazing to see that you have already finished the changes so quickly. I'm sorry that I didn't have time today to modify and support Python 3.8.

log-config.yml is unnecessary and can be deleted.

I agree that you keep 'frontend_cn.py' unchanged.

@lewangdev
Copy link
Contributor Author

Thank you for confirming that. Could you please make the necessary updates as we discussed, so that I can easily merge the PR?

Great!
it's amazing to see that you have already finished the changes so quickly. I'm sorry that I didn't have time today to modify and support Python 3.8.
log-config.yml is unnecessary and can be deleted.
I agree that you keep 'frontend_cn.py' unchanged.

ok.

@lewangdev
Copy link
Contributor Author

Hi, the PR has been updated.

@syq163 syq163 merged commit 857f2b2 into netease-youdao:main Dec 1, 2023
@syq163
Copy link
Collaborator

syq163 commented Dec 1, 2023

Thank you and all the best!

@lucasjinreal
Copy link

Hi, this is good, but if there is no-stream support, we can not say supported openai API now.

At least 2 things not done:

  1. Chinese support;
  2. streaming tts support;

@newbei
Copy link

newbei commented Apr 11, 2024

Can give a demo?

@qqedp045
Copy link

curl -X POST -H "Content-Type: application/json" -d '{"voice":"8051","input":"这里有一个改进的版本,使用了一个简单的轮询机制来等待文件生成。"}' http://192.168.21.133:8000/v1/audio/speech > o.mp3
@newbei
input: str
voice: str = '8051'
prompt: Optional[str] = ''
language: Optional[str] = 'zh_us'
model: Optional[str] = 'emoti-voice'
response_format: Optional[str] = 'mp3'
speed: Optional[float] = 1.0

还有其他参数,我最想知道的是prompt的用处。

@qqedp045
Copy link

def openai_audio(text: str, outPath: str):
headers = {
'Content-Type':'application/json'
}
url = "http://XXXXXXXX:8080/v1/audio/speech"
query = {
"model":"emoti-voice",
"input":text,
"voice":"984",
"response_format":"mp3",
"speed":1,
}
response = requests.post(url=url, data=json.dumps(query), headers=headers)
# 保存文件
f = open(outPath, "wb")
f.write(response.content)
f.close()

@xushilundao
Copy link

this is a test API cpde and it works,you can copy and paste it:
import requests
import json

def openai_audio(text: str, outPath: str):
headers = {
'Content-Type': 'application/json'
}
url = "http://localhost:8000/v1/audio/speech"
query = {
"model": "emoti-voice",
"input": text, # 使用传入的文本参数
"voice": "984",
"response_format": "mp3",
"speed": 1,
}
response = requests.post(url=url, data=json.dumps(query), headers=headers)

# 检查请求是否成功
if response.status_code == 200:
    # 保存文件
    with open(outPath, "wb") as f:
        f.write(response.content)
    print(f"Audio saved to {outPath}")
else:
    print(f"Failed to get audio. Status code: {response.status_code}")
    print(f"Response: {response.text}")

主程序调用部分

if name == "main":
text = "调试成功,调用TTS成功"
output_path = "output.mp3"
openai_audio(text, output_path)

@xushilundao
Copy link

_ No description provided. _
I've already run this API code correctly ,but how can I integrate with this to the config file of 火火兔 ?
Cause there is NO key in the api file. How can I config the TTS section in docker-compose.yml?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: clean the code and make a fastapi just like OpenAI's tts API
6 participants