Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -89,7 +89,7 @@ def translate_to_english(api_key, text, lang_code):
|
|
89 |
prompt = f"Translate the following text from {lang_code} to English: \n\n{text}"
|
90 |
|
91 |
response = openai.ChatCompletion.create(
|
92 |
-
model="gpt-
|
93 |
messages=[
|
94 |
{"role": "system", "content": "You are a helpful assistant that translates text."},
|
95 |
{"role": "user", "content": prompt}
|
@@ -134,8 +134,11 @@ if st.button('Generate Audio') and openai_api_key:
|
|
134 |
# Translate the input text to English using OpenAI
|
135 |
translated_text = translate_to_english(openai_api_key, input_text, lang_code)
|
136 |
|
|
|
|
|
|
|
137 |
# Generate audio for the translated English text
|
138 |
-
translated_audio_buffer = generate_audio(translated_text, 'a',
|
139 |
|
140 |
# Display Audio for the translated text
|
141 |
st.write(f"Translated Text: {translated_text}")
|
|
|
89 |
prompt = f"Translate the following text from {lang_code} to English: \n\n{text}"
|
90 |
|
91 |
response = openai.ChatCompletion.create(
|
92 |
+
model="gpt-4", # Using ChatGPT model for translation
|
93 |
messages=[
|
94 |
{"role": "system", "content": "You are a helpful assistant that translates text."},
|
95 |
{"role": "user", "content": prompt}
|
|
|
134 |
# Translate the input text to English using OpenAI
|
135 |
translated_text = translate_to_english(openai_api_key, input_text, lang_code)
|
136 |
|
137 |
+
# **Important Change**: Set the voice to a British English voice for translated text
|
138 |
+
english_voice = 'af_heart' # You can use other British voices such as 'af_nicole', 'af_river', etc.
|
139 |
+
|
140 |
# Generate audio for the translated English text
|
141 |
+
translated_audio_buffer = generate_audio(translated_text, 'a', english_voice, speed)
|
142 |
|
143 |
# Display Audio for the translated text
|
144 |
st.write(f"Translated Text: {translated_text}")
|