add logging
Browse files- app.py +7 -5
- fish_audio.py +6 -2
app.py
CHANGED
|
@@ -42,7 +42,7 @@ def get_text_from_url(url):
|
|
| 42 |
# You might want to add more sophisticated handling here
|
| 43 |
return response.text
|
| 44 |
except requests.exceptions.RequestException as e:
|
| 45 |
-
|
| 46 |
return None
|
| 47 |
|
| 48 |
def is_url(string):
|
|
@@ -70,7 +70,7 @@ def voice_transfer():
|
|
| 70 |
file.save(voice_file_path)
|
| 71 |
|
| 72 |
text_input = request.form.get('text')
|
| 73 |
-
|
| 74 |
if not text_input:
|
| 75 |
return jsonify({"error": "No text or text_url provided"}), 400
|
| 76 |
|
|
@@ -80,11 +80,11 @@ def voice_transfer():
|
|
| 80 |
if text_content is None:
|
| 81 |
return jsonify({"error": "Failed to retrieve or parse content from URL"}), 400
|
| 82 |
else:
|
| 83 |
-
|
| 84 |
text_content = text_input
|
| 85 |
|
| 86 |
# --- Perform Voice Cloning using Fish Audio ---
|
| 87 |
-
|
| 88 |
|
| 89 |
output_filename = f"output_cloned_{uuid.uuid4().hex}.mp3"
|
| 90 |
output_file_path = os.path.join(temp_dir, output_filename)
|
|
@@ -99,9 +99,11 @@ def voice_transfer():
|
|
| 99 |
reference_text="This is a reference audio for voice cloning."
|
| 100 |
)
|
| 101 |
except Exception as e:
|
| 102 |
-
|
| 103 |
return jsonify({"error": "Failed to generate voice file."}), 500
|
| 104 |
|
|
|
|
|
|
|
| 105 |
# Read the generated file into a memory buffer
|
| 106 |
with open(output_file_path, 'rb') as f:
|
| 107 |
audio_buffer = io.BytesIO(f.read())
|
|
|
|
| 42 |
# You might want to add more sophisticated handling here
|
| 43 |
return response.text
|
| 44 |
except requests.exceptions.RequestException as e:
|
| 45 |
+
app.logger.error(f"Error fetching URL: {e}")
|
| 46 |
return None
|
| 47 |
|
| 48 |
def is_url(string):
|
|
|
|
| 70 |
file.save(voice_file_path)
|
| 71 |
|
| 72 |
text_input = request.form.get('text')
|
| 73 |
+
app.logger.info(f"Received text input: {text_input}")
|
| 74 |
if not text_input:
|
| 75 |
return jsonify({"error": "No text or text_url provided"}), 400
|
| 76 |
|
|
|
|
| 80 |
if text_content is None:
|
| 81 |
return jsonify({"error": "Failed to retrieve or parse content from URL"}), 400
|
| 82 |
else:
|
| 83 |
+
app.logger.info("Input is not a URL, using as raw text.")
|
| 84 |
text_content = text_input
|
| 85 |
|
| 86 |
# --- Perform Voice Cloning using Fish Audio ---
|
| 87 |
+
app.logger.info("Starting voice cloning process with Fish Audio...")
|
| 88 |
|
| 89 |
output_filename = f"output_cloned_{uuid.uuid4().hex}.mp3"
|
| 90 |
output_file_path = os.path.join(temp_dir, output_filename)
|
|
|
|
| 99 |
reference_text="This is a reference audio for voice cloning."
|
| 100 |
)
|
| 101 |
except Exception as e:
|
| 102 |
+
app.logger.error(f"Error during voice cloning with Fish Audio: {e}")
|
| 103 |
return jsonify({"error": "Failed to generate voice file."}), 500
|
| 104 |
|
| 105 |
+
app.logger.info(f"Successfully generated audio file at: {output_file_path}")
|
| 106 |
+
|
| 107 |
# Read the generated file into a memory buffer
|
| 108 |
with open(output_file_path, 'rb') as f:
|
| 109 |
audio_buffer = io.BytesIO(f.read())
|
fish_audio.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
import os
|
| 2 |
import re
|
| 3 |
from fish_audio_sdk import Session, TTSRequest, ReferenceAudio
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def clone_voice_with_fish(text: str, reference_audio_path: str, output_path: str, reference_text: str = "Text in reference audio"):
|
| 6 |
"""
|
|
@@ -17,7 +21,7 @@ def clone_voice_with_fish(text: str, reference_audio_path: str, output_path: str
|
|
| 17 |
|
| 18 |
# Remove special words (e.g., __Gutenberg__, _very_)
|
| 19 |
text = re.sub(r'__\w+__\s*|_\w+_\s*', '', text)
|
| 20 |
-
|
| 21 |
|
| 22 |
# Load the API key from an environment variable for security.
|
| 23 |
api_key = os.getenv("FISH_AUDIO_API_KEY")
|
|
@@ -39,7 +43,7 @@ def clone_voice_with_fish(text: str, reference_audio_path: str, output_path: str
|
|
| 39 |
]
|
| 40 |
)):
|
| 41 |
f.write(chunk)
|
| 42 |
-
|
| 43 |
|
| 44 |
if __name__ == '__main__':
|
| 45 |
# This is an example of how to use the function.
|
|
|
|
| 1 |
import os
|
| 2 |
import re
|
| 3 |
from fish_audio_sdk import Session, TTSRequest, ReferenceAudio
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
# Configure basic logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 8 |
|
| 9 |
def clone_voice_with_fish(text: str, reference_audio_path: str, output_path: str, reference_text: str = "Text in reference audio"):
|
| 10 |
"""
|
|
|
|
| 21 |
|
| 22 |
# Remove special words (e.g., __Gutenberg__, _very_)
|
| 23 |
text = re.sub(r'__\w+__\s*|_\w+_\s*', '', text)
|
| 24 |
+
logging.info(f"Text for TTS: {text}")
|
| 25 |
|
| 26 |
# Load the API key from an environment variable for security.
|
| 27 |
api_key = os.getenv("FISH_AUDIO_API_KEY")
|
|
|
|
| 43 |
]
|
| 44 |
)):
|
| 45 |
f.write(chunk)
|
| 46 |
+
logging.info(f"File output to: {output_path}")
|
| 47 |
|
| 48 |
if __name__ == '__main__':
|
| 49 |
# This is an example of how to use the function.
|