ariankhalfani commited on
Commit
5ddeb31
·
verified ·
1 Parent(s): 8dab310

Update LLMwithvoice.py

Browse files
Files changed (1) hide show
  1. LLMwithvoice.py +12 -9
LLMwithvoice.py CHANGED
@@ -33,8 +33,17 @@ def generate_speech(prompt, description):
33
 
34
  generation = model.generate(input_ids=input_ids, prompt_input_ids=prompt_input_ids).to(torch.float32)
35
  audio_arr = generation.cpu().numpy().squeeze()
36
- audio_path = "/mnt/data/parler_tts_out.wav"
37
- sf.write(audio_path, audio_arr, model.config.sampling_rate)
 
 
 
 
 
 
 
 
 
38
  return audio_path
39
 
40
  def chat_with_roberta(api_token, question, context):
@@ -51,10 +60,4 @@ def chat_with_roberta(api_token, question, context):
51
  try:
52
  return response['answer']
53
  except (IndexError, KeyError):
54
- return f"Unexpected response structure: {response}"
55
-
56
- def gradio_interface(api_token, context, question):
57
- answer = chat_with_roberta(api_token, question, context)
58
- description = "A female speaker with a slightly low-pitched voice delivers her words quite expressively, in a very confined sounding environment with clear audio quality. She speaks very fast."
59
- audio_path = generate_speech(answer, description)
60
- return answer, audio_path
 
33
 
34
  generation = model.generate(input_ids=input_ids, prompt_input_ids=prompt_input_ids).to(torch.float32)
35
  audio_arr = generation.cpu().numpy().squeeze()
36
+
37
+ # Construct the audio path dynamically
38
+ audio_filename = "parler_tts_out.wav"
39
+ audio_path = f"/mnt/data/{audio_filename}"
40
+
41
+ try:
42
+ sf.write(audio_path, audio_arr, model.config.sampling_rate)
43
+ except Exception as e:
44
+ print(f"Error writing audio file: {e}")
45
+ # Handle the error, raise or log it, or provide an alternative approach
46
+
47
  return audio_path
48
 
49
  def chat_with_roberta(api_token, question, context):
 
60
  try:
61
  return response['answer']
62
  except (IndexError, KeyError):
63
+ return f"Unexpected response structure: {response}"