gorkemgoknar commited on
Commit
baead3d
1 Parent(s): b5961c0

language detection fix

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -559,11 +559,19 @@ second_of_silence.export("sil.wav", format='wav')
559
  def generate_speech(history,chatbot_role):
560
  # Must set autoplay to True first
561
  yield (history, chatbot_role, "", wave_header_chunk() )
 
 
 
 
562
  for sentence, history in get_sentence(history,chatbot_role):
563
  if sentence != "":
 
 
 
 
564
  print("BG: inserting sentence to queue")
565
 
566
- generated_speech = generate_speech_for_sentence(history, chatbot_role, sentence,return_as_byte=True)
567
  if generated_speech is not None:
568
  _, audio_dict = generated_speech
569
  # We are using byte streaming
@@ -571,9 +579,8 @@ def generate_speech(history,chatbot_role):
571
 
572
 
573
  # will generate speech audio file per sentence
574
- def generate_speech_for_sentence(history, chatbot_role, sentence, return_as_byte=True):
575
- language = "autodetect"
576
-
577
  wav_bytestream = b""
578
 
579
  if len(sentence)==0:
 
559
  def generate_speech(history,chatbot_role):
560
  # Must set autoplay to True first
561
  yield (history, chatbot_role, "", wave_header_chunk() )
562
+
563
+ first_sentence=True
564
+ language="autodetect" # will predict from first sentence
565
+
566
  for sentence, history in get_sentence(history,chatbot_role):
567
  if sentence != "":
568
+ if first_sentence:
569
+ language = detect_language(sentence)
570
+ first_sentence=False
571
+
572
  print("BG: inserting sentence to queue")
573
 
574
+ generated_speech = generate_speech_for_sentence(history, chatbot_role, sentence,return_as_byte=True,language=language)
575
  if generated_speech is not None:
576
  _, audio_dict = generated_speech
577
  # We are using byte streaming
 
579
 
580
 
581
  # will generate speech audio file per sentence
582
+ def generate_speech_for_sentence(history, chatbot_role, sentence, return_as_byte=True, language="autodetect"):
583
+
 
584
  wav_bytestream = b""
585
 
586
  if len(sentence)==0: