Skip to content

Commit

Permalink
Modify the FastAPI code to be compatible with Python 3.8+
Browse files Browse the repository at this point in the history
  • Loading branch information
lewangdev committed Dec 1, 2023
1 parent e0750c2 commit f9b90f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 59 deletions.
29 changes: 13 additions & 16 deletions frontend_cn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@

re_special_pinyin = re.compile(r'^(n|ng|m)$')
def split_py(py):
if len(py) == 0:
return "", ""
tone = py[-1]
py = py[:-1]
sm = ""
ym = ""
suf_r = ""
if re_special_pinyin.match(py):
py = 'e' + py
if len(py) != 0 and py[-1] == 'r':
if py[-1] == 'r':
suf_r = 'r'
py = py[:-1]
if py == 'zi' or py == 'ci' or py == 'si' or py == 'ri':
Expand All @@ -50,25 +48,24 @@ def split_py(py):
elif py == 'wu':
sm = ""
ym = "u"
elif len(py) != 0 and py[0] == 'w':
elif py[0] == 'w':
sm = ""
ym = "u" + py[1:]
elif len(py) >= 2 and (py[0] == 'j' or py[0] == 'q' or py[0] == 'x') and py[1] == 'u':
sm = py[0]
ym = 'v' + py[2:]
else:
seg_pos = re.search('a|e|i|o|u|v', py)
if seg_pos is not None:
sm = py[:seg_pos.start()]
ym = py[seg_pos.start():]
if ym == 'ui':
ym = 'uei'
elif ym == 'iu':
ym = 'iou'
elif ym == 'un':
ym = 'uen'
elif ym == 'ue':
ym = 've'
sm = py[:seg_pos.start()]
ym = py[seg_pos.start():]
if ym == 'ui':
ym = 'uei'
elif ym == 'iu':
ym = 'iou'
elif ym == 'un':
ym = 'uen'
elif ym == 'ue':
ym = 've'
ym += suf_r + tone
return sm, ym

Expand Down Expand Up @@ -118,7 +115,7 @@ def g2p_cn(text):

res_text.append(" sp0 ".join(py))
res_text.append("sp1")
res_text.pop()
#res_text.pop()
res_text.append("<sos/eos>")
return " ".join(res_text)

Expand Down
34 changes: 0 additions & 34 deletions log-config.yml

This file was deleted.

16 changes: 7 additions & 9 deletions openaiapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dotenv
import logging
import os
import io
Expand All @@ -19,7 +18,6 @@
from config.joint.config import Config

LOGGER = logging.getLogger(__name__)
dotenv.load_dotenv()

DEFAULTS = {
}
Expand Down Expand Up @@ -147,15 +145,15 @@ def emotivoice_tts(text, prompt, content, speaker, models):
models = get_models()
app = FastAPI()


from typing import Optional
class SpeechRequest(BaseModel):
input: str
voice: str = '8051'
prompt: str | None = ''
language: str | None = 'zh_us'
model: str | None = 'emoti-voice'
response_format: str | None = 'mp3'
speed: float | None = 1.0
prompt: Optional[str] = ''
language: Optional[str] = 'zh_us'
model: Optional[str] = 'emoti-voice'
response_format: Optional[str] = 'mp3'
speed: Optional[float] = 1.0


@app.post("/v1/audio/speech")
Expand All @@ -166,7 +164,7 @@ def text_to_speech(speechRequest: SpeechRequest):
speechRequest.input, speechRequest.voice,
models)
wav_buffer = io.BytesIO()
sf.write(wav_buffer, data=np_audio,
sf.write(file=wav_buffer, data=np_audio,
samplerate=config.sampling_rate, format='WAV')
buffer = wav_buffer
response_format = speechRequest.response_format
Expand Down

0 comments on commit f9b90f3

Please sign in to comment.