Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,7 @@ import uuid
|
|
| 4 |
from flask import Flask, request, render_template, jsonify, send_from_directory, session
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
from groq import Groq
|
| 7 |
-
from deepgram import
|
| 8 |
-
from deepgram import SpeakOptions # This might not exist in the current SDK; adjust as needed
|
| 9 |
|
| 10 |
# Load environment variables
|
| 11 |
load_dotenv()
|
|
@@ -39,10 +38,11 @@ def synthesize_audio(text, model="aura-asteria-en"):
|
|
| 39 |
unique_filename = f"therapist_response_{int(time.time())}_{uuid.uuid4().hex}.mp3"
|
| 40 |
filename = os.path.join(audio_folder, unique_filename)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
deepgram.speak.v("1").save(filename, {"text": text}, options)
|
| 45 |
-
|
| 46 |
return filename
|
| 47 |
except Exception as e:
|
| 48 |
raise ValueError(f"Speech synthesis failed: {str(e)}")
|
|
@@ -61,6 +61,7 @@ def start_chat():
|
|
| 61 |
session['selected_voice'] = selected_voice
|
| 62 |
return render_template('index.html')
|
| 63 |
|
|
|
|
| 64 |
@app.route('/process', methods=['POST'])
|
| 65 |
def process_audio():
|
| 66 |
global conversation_history
|
|
@@ -123,5 +124,4 @@ def process_audio():
|
|
| 123 |
return jsonify({'error': str(e)}), 500
|
| 124 |
|
| 125 |
if __name__ == '__main__':
|
| 126 |
-
|
| 127 |
-
app.run(host="0.0.0.0", port=7860, debug=True)
|
|
|
|
| 4 |
from flask import Flask, request, render_template, jsonify, send_from_directory, session
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
from groq import Groq
|
| 7 |
+
from deepgram import DeepgramClient, SpeakOptions
|
|
|
|
| 8 |
|
| 9 |
# Load environment variables
|
| 10 |
load_dotenv()
|
|
|
|
| 38 |
unique_filename = f"therapist_response_{int(time.time())}_{uuid.uuid4().hex}.mp3"
|
| 39 |
filename = os.path.join(audio_folder, unique_filename)
|
| 40 |
|
| 41 |
+
options = SpeakOptions(
|
| 42 |
+
model=model
|
| 43 |
+
)
|
| 44 |
+
# Synthesize the response and save it to the file
|
| 45 |
deepgram.speak.v("1").save(filename, {"text": text}, options)
|
|
|
|
| 46 |
return filename
|
| 47 |
except Exception as e:
|
| 48 |
raise ValueError(f"Speech synthesis failed: {str(e)}")
|
|
|
|
| 61 |
session['selected_voice'] = selected_voice
|
| 62 |
return render_template('index.html')
|
| 63 |
|
| 64 |
+
|
| 65 |
@app.route('/process', methods=['POST'])
|
| 66 |
def process_audio():
|
| 67 |
global conversation_history
|
|
|
|
| 124 |
return jsonify({'error': str(e)}), 500
|
| 125 |
|
| 126 |
if __name__ == '__main__':
|
| 127 |
+
app.run(debug=True)
|
|
|