cnph001 commited on
Commit
5eeb00f
·
verified ·
1 Parent(s): cf1d09e

Update app.py

Browse files

Insert Silence.mp3 to section where marker "SSxxx" is found

Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -33,9 +33,12 @@ async def paragraph_to_speech(text, voice, rate, pitch):
33
  for part in parts:
34
  if re.match(r'SS\d+\.?\d*', part):
35
  try:
36
- silence_duration = float(part[2:])
37
- silence_durations.append(silence_duration)
38
- audio_segments.append(None) # Placeholder for silence
 
 
 
39
  except ValueError:
40
  print(f"Warning: Invalid silence duration format: {part}")
41
  elif part.strip():
@@ -43,7 +46,6 @@ async def paragraph_to_speech(text, voice, rate, pitch):
43
  current_voice = voice
44
  current_rate = rate
45
  current_pitch = pitch
46
-
47
  if part.startswith("1F"):
48
  processed_text = part[2:]
49
  current_voice = voice1F.split(" - ")[0]
@@ -121,11 +123,6 @@ async def text_to_speech(text, voice, rate, pitch):
121
  os.remove(segment) # Clean up individual files
122
  except FileNotFoundError:
123
  print(f"Warning: Audio file not found: {segment}")
124
- elif isinstance(segment, (int, float)):
125
- # Basic silence insertion (approximate)
126
- silence = b'\x00' * int(segment * 44100 * 2) # Assuming 16-bit mono at 44.1kHz
127
- outfile.write(silence)
128
-
129
  return combined_audio_path, None
130
 
131
  # Gradio interface function
@@ -142,7 +139,7 @@ async def create_demo():
142
  default_voice = "en-US-AndrewMultilingualNeural - en-US (Male)" # 👈 Pick one of the available voices
143
  description = """
144
  Default = male, other voices 1F:US_Emma, 2F:US_Jenny, 3F:HK_Yan, 1M:AU_Will, 2M:IT_Guiseppe,3M:US_Brian, 1C: Childvoice, 1O = OldMan
145
- You can insert silence using the marker 'SS' followed by the duration in seconds (e.g., 'SS1.2' for a 1.2-second pause).
146
  Enter your text, select a voice, and adjust the speech rate and pitch.
147
  The application will process your text paragraph by paragraph (separated by two blank lines).
148
  """
 
33
  for part in parts:
34
  if re.match(r'SS\d+\.?\d*', part):
35
  try:
36
+ #silence_duration = float(part[2:])
37
+ silence_path = os.path.join(os.path.dirname(__file__), "Silence.mp3")
38
+ if os.path.exists(silence_path):
39
+ audio_segments.append(silence_path)
40
+ else:
41
+ print(f"Warning: Silence.mp3 not found at {silence_path}")
42
  except ValueError:
43
  print(f"Warning: Invalid silence duration format: {part}")
44
  elif part.strip():
 
46
  current_voice = voice
47
  current_rate = rate
48
  current_pitch = pitch
 
49
  if part.startswith("1F"):
50
  processed_text = part[2:]
51
  current_voice = voice1F.split(" - ")[0]
 
123
  os.remove(segment) # Clean up individual files
124
  except FileNotFoundError:
125
  print(f"Warning: Audio file not found: {segment}")
 
 
 
 
 
126
  return combined_audio_path, None
127
 
128
  # Gradio interface function
 
139
  default_voice = "en-US-AndrewMultilingualNeural - en-US (Male)" # 👈 Pick one of the available voices
140
  description = """
141
  Default = male, other voices 1F:US_Emma, 2F:US_Jenny, 3F:HK_Yan, 1M:AU_Will, 2M:IT_Guiseppe,3M:US_Brian, 1C: Childvoice, 1O = OldMan
142
+ You can insert silence using the marker 'SS' (This will insert a Silence period from the Silence.mp3 file).
143
  Enter your text, select a voice, and adjust the speech rate and pitch.
144
  The application will process your text paragraph by paragraph (separated by two blank lines).
145
  """