-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext-to-speech.py
More file actions
48 lines (40 loc) · 1.33 KB
/
Copy pathtext-to-speech.py
File metadata and controls
48 lines (40 loc) · 1.33 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import whisper
import os
# Function to load the model and handle errors
def load_model():
try:
model = whisper.load_model("base") # You can change to "small", "medium", or "large"
return model
except Exception as e:
print(f"Error loading the model: {e}")
return None
# Function to transcribe audio
def transcribe_audio(model, audio_path):
if not os.path.exists(audio_path):
print("Error: Audio file does not exist.")
return None
try:
# Perform transcription
result = model.transcribe(audio_path)
return result['text']
except Exception as e:
print(f"Error transcribing audio: {e}")
return None
# Main code execution
def main():
# Load the Whisper model
model = load_model()
if model:
# Path to the audio file
audio_path = r"C:\Users\rtx11\Downloads\newsroundup.wav" # Update with your actual audio file path
# Transcribe the audio
transcription = transcribe_audio(model, audio_path)
if transcription:
print("Transcription: ", transcription)
else:
print("Transcription failed.")
else:
print("Failed to load Whisper model.")
# Run the main function
if __name__ == "__main__":
main()