Spaces:
Runtime error
Runtime error
import whisper | |
from gtts import gTTS | |
from pydub import AudioSegment | |
#text to sppech function | |
def text_to_speech(text): | |
# Convert text to speech with a US accent using gTTS | |
tts = gTTS(text=text, lang='en', tld='us', slow=False) | |
tts.save('temp.mp3') | |
# Load the audio file | |
audio = AudioSegment.from_file('temp.mp3') | |
# Adjust the speed to approximately 170 wpm | |
playback_speed = 1.20 | |
audio = audio.speedup(playback_speed=playback_speed) | |
# Save and return the adjusted audio file | |
final_filename = 'text_to_speech.mp3' | |
audio.export(final_filename, format='mp3') | |
return final_filename | |
#speech to text function | |
def audio_to_text(audio): | |
model = whisper.load_model("base.en") | |
result = model.transcribe(audio) | |
return result["text"] | |