PhilSpiel commited on
Commit
a0f4c75
·
1 Parent(s): 01d333a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -23
app.py CHANGED
@@ -12,7 +12,7 @@ elevenlabs_api_key = os.getenv("ELEVENLABS_API_KEY")
12
 
13
  # Define the function that generates the speech
14
  def generate_speech(input_text):
15
- # Build completion with OpenAI (ChatGPT part)
16
  completion = client.chat.completions.create(
17
  model="gpt-3.5-turbo-1106",
18
  messages=[
@@ -22,15 +22,12 @@ def generate_speech(input_text):
22
  ]
23
  )
24
 
25
- # Extract generated text from API response
26
- message_content = completion.choices[0].message.content # Access the message content attribute
27
- text_in_quotes = re.findall(r'"([^"]*)"', message_content) # This should be a list of found quotes
28
 
29
- # Make sure that text_in_quotes is a single string (concatenate if required)
30
- if text_in_quotes:
31
- text_to_speech = " ".join(text_in_quotes) # Join all found quotes into a single string
32
- else:
33
- text_to_speech = "No quotes found in the message." # Fallback message
34
 
35
  # ElevenLabs TTS API settings and request
36
  url = "https://api.elevenlabs.io/v1/text-to-speech/eIH76iW9yjOWnOKIkd6y/generate"
@@ -39,23 +36,13 @@ else:
39
  "Content-Type": "application/json"
40
  }
41
  data = {
42
- "text": text_in_quotes,
43
- "model_id": "eleven_multilingual_v2",
44
- "voice_settings": {
45
- "stability": 1.0,
46
- "similarity_boost": 1.0,
47
- "excitement": 0.9,
48
- "speed": 1.1,
49
- "volume": 80,
50
- "pitch": 2.0,
51
- "breathiness": 0.8,
52
- "voice_id": "eIH76iW9yjOWnOKIkd6y"
53
- }
54
- }
55
  response = requests.post(url, json=data, headers=headers)
56
 
 
57
  if response.status_code == 200:
58
- # Assuming ElevenLabs returns the audio file directly
59
  return response.content
60
  else:
61
  print("Error with ElevenLabs API:", response.text)
 
12
 
13
  # Define the function that generates the speech
14
  def generate_speech(input_text):
15
+ # Build completion with OpenAI
16
  completion = client.chat.completions.create(
17
  model="gpt-3.5-turbo-1106",
18
  messages=[
 
22
  ]
23
  )
24
 
25
+ # Extract generated text from API response
26
+ message_content = completion.choices[0].message.content
27
+ text_in_quotes = re.findall(r'"([^"]*)"', message_content)
28
 
29
+ # Make sure that text_in_quotes is a single string (concatenate if required)
30
+ text_to_speech = " ".join(text_in_quotes) if text_in_quotes else "No quotes found in the message."
 
 
 
31
 
32
  # ElevenLabs TTS API settings and request
33
  url = "https://api.elevenlabs.io/v1/text-to-speech/eIH76iW9yjOWnOKIkd6y/generate"
 
36
  "Content-Type": "application/json"
37
  }
38
  data = {
39
+ "text": text_to_speech,
40
+ # ... Other settings you provided
41
+ }
 
 
 
 
 
 
 
 
 
 
42
  response = requests.post(url, json=data, headers=headers)
43
 
44
+ # Return the response content directly if successful, otherwise raise an exception
45
  if response.status_code == 200:
 
46
  return response.content
47
  else:
48
  print("Error with ElevenLabs API:", response.text)