Pendrokar commited on
Commit
c26c08b
·
1 Parent(s): ffe17d7

IPA re-insert

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -56,9 +56,10 @@ def text_to_ipa(text, lang='en-us'):
56
 
57
  try:
58
  # Handle IPA sections within brackets
59
- regex = r"\[[^\]]*\]"
60
  ipa_sections = re.findall(regex, text)
61
- text = re.sub(regex, '[]', text)
 
62
  print(text)
63
 
64
  if lang == 'jb':
@@ -75,7 +76,8 @@ def text_to_ipa(text, lang='en-us'):
75
 
76
  # Add back IPA sections
77
  for ipa in ipa_sections:
78
- ps = ps.replace('[ ]', ipa, 1)
 
79
 
80
  return ps
81
  except Exception as e:
@@ -115,6 +117,16 @@ def generate_first(text, voice='af_heart', speed=1, use_gpu=CUDA_AVAILABLE, lang
115
 
116
  # Arena API
117
  def predict(text, voice='af_heart', speed=1):
 
 
 
 
 
 
 
 
 
 
118
  return generate_first(text, voice, speed, use_gpu=False)[0]
119
 
120
  def tokenize_first(text, voice='af_heart', lang='en-us'):
 
56
 
57
  try:
58
  # Handle IPA sections within brackets
59
+ regex = r"\([^\]]*\)[[^\]]*\]"
60
  ipa_sections = re.findall(regex, text)
61
+ print(text)
62
+ text = re.sub(regex, '()[]', text)
63
  print(text)
64
 
65
  if lang == 'jb':
 
76
 
77
  # Add back IPA sections
78
  for ipa in ipa_sections:
79
+ ps = ps.replace('( )[ ]', ipa, 1)
80
+ print(ps)
81
 
82
  return ps
83
  except Exception as e:
 
117
 
118
  # Arena API
119
  def predict(text, voice='af_heart', speed=1):
120
+ """ Convert the text to speech using StyleTTS 2.
121
+
122
+ Args:
123
+ text: string; accepts IPA within ()[] brackets
124
+ voice: Literal['af_heart', 'af_bella', 'af_nicole', 'af_aoede', 'af_kore', 'af_sarah', 'af_nova', 'af_sky', 'af_alloy', 'af_jessica', 'af_river', 'am_michael', 'am_fenrir', 'am_puck', 'am_echo', 'am_eric', 'am_liam', 'am_onyx', 'am_santa', 'am_adam', 'bf_emma', 'bf_isabella', 'bf_alice', 'bf_lily', 'bm_george', 'bm_fable', 'bm_lewis', 'bm_daniel']; voice model
125
+ lang: Literal['en-us', 'cs', 'da', 'nl', 'et', 'fi', 'fr', 'de', 'el', 'it', 'no', 'pl', 'pt', 'ru', 'sl', 'es', 'sv', 'tr', 'jb']; ISO 639-1 code for the text language; 'jb' is a valid code for Lojban
126
+ speed: talkback speed; 0.5-2
127
+
128
+ Returns: Tuple of (output_audio_path, ipa_results) where output_audio_path is the filepath of output audio
129
+ """
130
  return generate_first(text, voice, speed, use_gpu=False)[0]
131
 
132
  def tokenize_first(text, voice='af_heart', lang='en-us'):