mac9087 commited on
Commit
d997bfa
·
verified ·
1 Parent(s): 6f2d6ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -6,6 +6,7 @@ from TTS.api import TTS
6
  import tempfile
7
  import os
8
  import re
 
9
 
10
  app = Flask(__name__)
11
  CORS(app)
@@ -68,8 +69,19 @@ def process_response(input_text, generated_text):
68
  # Remove any repetitive phrases
69
  result = remove_repetitions(result)
70
 
 
 
 
71
  return result
72
 
 
 
 
 
 
 
 
 
73
  def remove_repetitions(text):
74
  # Simple repetition removal
75
  words = text.split()
@@ -169,8 +181,12 @@ def talk():
169
  # Return both the audio file and the text response
170
  try:
171
  response = send_file(tts_audio_path, mimetype="audio/wav")
172
- response.headers["X-Response-Text"] = final_response
173
- response.headers["Access-Control-Expose-Headers"] = "X-Response-Text"
 
 
 
 
174
  return response
175
  except Exception as e:
176
  print(f"Error sending file: {str(e)}")
 
6
  import tempfile
7
  import os
8
  import re
9
+ import base64
10
 
11
  app = Flask(__name__)
12
  CORS(app)
 
69
  # Remove any repetitive phrases
70
  result = remove_repetitions(result)
71
 
72
+ # Normalize quotes to ASCII equivalents
73
+ result = normalize_quotes(result)
74
+
75
  return result
76
 
77
+ def normalize_quotes(text):
78
+ """Replace curly quotes and other problematic Unicode characters with ASCII equivalents"""
79
+ # Replace curly quotes with straight quotes
80
+ text = text.replace('"', '"').replace('"', '"')
81
+ text = text.replace(''', "'").replace(''', "'")
82
+ # Add more replacements as needed
83
+ return text
84
+
85
  def remove_repetitions(text):
86
  # Simple repetition removal
87
  words = text.split()
 
181
  # Return both the audio file and the text response
182
  try:
183
  response = send_file(tts_audio_path, mimetype="audio/wav")
184
+
185
+ # Base64 encode the response text to avoid Unicode issues in headers
186
+ encoded_response = base64.b64encode(final_response.encode('utf-8')).decode('ascii')
187
+ response.headers["X-Response-Text-Base64"] = encoded_response
188
+ response.headers["Access-Control-Expose-Headers"] = "X-Response-Text-Base64"
189
+
190
  return response
191
  except Exception as e:
192
  print(f"Error sending file: {str(e)}")