Spaces:
Runtime error
Runtime error
File size: 819 Bytes
d64d27f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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"]
|