File tree Expand file tree Collapse file tree 4 files changed +36
-15
lines changed
Expand file tree Collapse file tree 4 files changed +36
-15
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ class SpeechRequest(BaseModel):
3030 )
3131 speed : Optional [float ] = Field (
3232 default = 1.0 ,
33- description = "The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default." ,
33+ description = "The speed of the generated audio. Select a value from 0.25 to 5.0. 1.0 is the default." ,
34+ ge = 0 ,
35+ le = 5 ,
3436 )
3537
3638
Original file line number Diff line number Diff line change 33- Chat Completions. (Reference: https://platform.openai.com/docs/api-reference/chat)
44- Completions. (Reference: https://platform.openai.com/docs/api-reference/completions)
55- Embeddings. (Reference: https://platform.openai.com/docs/api-reference/embeddings)
6-
7- Usage:
8- python3 -m fastchat.serve.openai_api_server
6+ - Moderations. (Reference: https://platform.openai.com/docs/api-reference/moderations)
7+ - Audio. (Reference: https://platform.openai.com/docs/api-reference/audio)
98"""
109
1110import asyncio
@@ -721,7 +720,14 @@ async def speech(request: SpeechRequest):
721720 )
722721 filename = f"{ uuid .uuid4 ()} .mp3"
723722 output_path = os .path .join (OUTPUT_DIR , filename )
724- communicate = edge_tts .Communicate (text = request .input , voice = request .voice )
723+ rate = 1.0
724+ if request .speed >= 1 :
725+ rate = f"+{ int ((request .speed - 1 ) * 100 )} %"
726+ else :
727+ rate = f"-{ int ((1 - request .speed ) * 100 )} %"
728+ communicate = edge_tts .Communicate (
729+ text = request .input , voice = request .voice , rate = rate
730+ )
725731 await communicate .save (output_path )
726732 return FileResponse (output_path , media_type = "audio/mpeg" , filename = filename )
727733
Original file line number Diff line number Diff line change 11from typing import Tuple
22
3- __version__ = "0.3.2 "
3+ __version__ = "0.3.5 "
44short_version = __version__
55
66
Original file line number Diff line number Diff line change 11from pathlib import Path
22from openai import OpenAI
3+ import asyncio
4+ import edge_tts
5+ from rich import print
36
4- # 新版本 opnai
5- client = OpenAI (api_key = "EMPTY" , base_url = "http://localhost:8082/v1" )
6- speech_file_path = Path (__file__ ).parent / "speech.mp3"
7- response = client .audio .speech .create (
8- model = "edge_tts" ,
9- voice = "zh-CN-YunxiNeural" ,
10- input = "你好啊,我是人工智能。" ,
11- )
12- response .write_to_file (speech_file_path )
7+
8+ async def main ():
9+ list_voices = await edge_tts .list_voices ()
10+ zh_list_voices = [i ["ShortName" ] for i in list_voices if "zh-CN" in i ["ShortName" ]]
11+ print (f"支持以下中文voice: \n { zh_list_voices } " )
12+ # 新版本 opnai
13+ client = OpenAI (api_key = "EMPTY" , base_url = "http://localhost:8082/v1" )
14+ speech_file_path = Path (__file__ ).parent / "speech.mp3"
15+ response = client .audio .speech .create (
16+ model = "edge_tts" ,
17+ voice = "zh-CN-YunxiNeural" ,
18+ input = "你好啊,我是人工智能。" ,
19+ speed = 1.0 ,
20+ )
21+ response .write_to_file (speech_file_path )
22+
23+
24+ if __name__ == "__main__" :
25+ asyncio .run (main ())
You can’t perform that action at this time.
0 commit comments