Pijush2023 commited on
Commit
6715849
·
verified ·
1 Parent(s): 3b80526

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -752,12 +752,13 @@ from threading import Thread
752
 
753
  repo_id = "parler-tts/parler-tts-mini-v1"
754
 
 
 
755
 
756
  def generate_audio_parler_tts(text):
757
  description = "A female speaker delivers a slightly expressive and animated speech with a moderate speed and pitch. The recording is of very high quality, with the speaker's voice sounding clear and very close up."
758
  chunk_size_in_s = 0.5
759
 
760
-
761
  # Initialize the tokenizer and model
762
  parler_tokenizer = AutoTokenizer.from_pretrained(repo_id)
763
  parler_model = ParlerTTSForConditionalGeneration.from_pretrained(repo_id).to(device)
@@ -788,6 +789,9 @@ def generate_audio_parler_tts(text):
788
  for new_audio in streamer:
789
  if new_audio.shape[0] == 0:
790
  break
 
 
 
791
  yield sampling_rate, new_audio
792
 
793
  audio_segments = []
@@ -809,7 +813,6 @@ def generate_audio_parler_tts(text):
809
 
810
 
811
 
812
-
813
  def fetch_local_events():
814
  api_key = os.environ['SERP_API']
815
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Birmingham&hl=en&gl=us&api_key={api_key}'
 
752
 
753
  repo_id = "parler-tts/parler-tts-mini-v1"
754
 
755
+ import sounddevice as sd # For real-time audio playback
756
+
757
 
758
  def generate_audio_parler_tts(text):
759
  description = "A female speaker delivers a slightly expressive and animated speech with a moderate speed and pitch. The recording is of very high quality, with the speaker's voice sounding clear and very close up."
760
  chunk_size_in_s = 0.5
761
 
 
762
  # Initialize the tokenizer and model
763
  parler_tokenizer = AutoTokenizer.from_pretrained(repo_id)
764
  parler_model = ParlerTTSForConditionalGeneration.from_pretrained(repo_id).to(device)
 
789
  for new_audio in streamer:
790
  if new_audio.shape[0] == 0:
791
  break
792
+ # Real-time playback of the audio chunk
793
+ sd.play(new_audio, samplerate=sampling_rate)
794
+ sd.wait() # Wait until the audio is played before moving to the next chunk
795
  yield sampling_rate, new_audio
796
 
797
  audio_segments = []
 
813
 
814
 
815
 
 
816
  def fetch_local_events():
817
  api_key = os.environ['SERP_API']
818
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Birmingham&hl=en&gl=us&api_key={api_key}'