Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Anning01 committed Aug 22, 2023
1 parent 9527a73 commit 545a79f
Show file tree
Hide file tree
Showing 25 changed files with 739 additions and 89 deletions.
15 changes: 7 additions & 8 deletions SDK/Baidu/Voice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Main:
client_id = client_id
client_secret = client_secret

async def create_access_token(self):
def create_access_token(self):
url = f"https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={self.client_id}&client_secret={self.client_secret}"
payload = ""
headers = {
Expand All @@ -34,22 +34,22 @@ async def create_access_token(self):
json.dump(access_token, f)
return access_token

async def get_access_token(self):
def get_access_token(self):
if os.path.exists('access_token.json'):
with open('access_token.json', 'r', encoding='utf-8') as f:
data = json.load(f)
time = data.get("time")
if time and (datetime.now() - datetime.strptime(time, '%Y-%m-%d')).days >= 29:
return await self.create_access_token()
return self.create_access_token()
return data
return await self.create_access_token()
return self.create_access_token()

async def text_to_audio(self, text: str, index: int, bookname=None, config=None):
def text_to_audio(self, text: str, index: int, bookname=None, config=None):
url = "https://tsn.baidu.com/text2audio"
text = text.encode('utf8')
FORMATS = {3: "mp3", 4: "pcm", 5: "pcm", 6: "wav"}
FORMAT = FORMATS[6]
access_token = await self.get_access_token()
access_token = self.get_access_token()
data = {
# 合成的文本,文本长度必须小于1024GBK字节。建议每次请求文本不超过120字节,约为60个汉字或者字母数字。
"tex": text,
Expand Down Expand Up @@ -120,5 +120,4 @@ async def text_to_audio(self, text: str, index: int, bookname=None, config=None)


if __name__ == '__main__':
import asyncio
asyncio.run(Main().text_to_audio("叶无名是一个少林寺的俗家弟子,他天资聪颖,博览群书,精通天文地理和阴阳八卦", 1))
Main().text_to_audio("叶无名是一个少林寺的俗家弟子,他天资聪颖,博览群书,精通天文地理和阴阳八卦", 1)
2 changes: 1 addition & 1 deletion SDK/ChatGPT/API2D/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Main:
def __str__(self):
return "API2D请求失败,请检查配置!"

async def prompt_generation_chatgpt(self, param):
def prompt_generation_chatgpt(self, param):
# 发送HTTP POST请求
headers = {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion SDK/ChatGPT/FastGPT/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Main:
def __str__(self):
return "FastGPT请求失败,请检查配置!"

async def prompt_generation_chatgpt(self, param):
def prompt_generation_chatgpt(self, param):
# 发送HTTP POST请求
headers = {
'Content-Type': 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions SDK/ChatGPT/openAI/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Main:
def __str__(self):
return "ChatGPT请求失败,请检查配置!"

async def prompt_generation_chatgpt(self, param):
def prompt_generation_chatgpt(self, param):
openai.api_key = openAPI_KEY

try:
Expand All @@ -58,4 +58,4 @@ async def prompt_generation_chatgpt(self, param):


if __name__ == '__main__':
asyncio.run(Main().prompt_generation_chatgpt("天空一声惊响,老子闪亮登场。"))
Main().prompt_generation_chatgpt("天空一声惊响,老子闪亮登场。")
Loading

0 comments on commit 545a79f

Please sign in to comment.