I want to implement whisper on VScode. I have tried this using 3.9.9 and 3.11 versions of python with the same error. audio is not getting loaded and I keep getting the File Not Found error. I have given the correct path for the audio.
import wave
import os
from IPython.display import Audio, display
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("Recording...")
frames = []
for i in range(0, int(RATE / CHUNK * duration_seconds)):
data = stream.read(CHUNK)
frames.append(data)
print("Finished recording.")
stream.stop_stream()
stream.close()
p.terminate()
file_name = "audio_30.wav" # You can customize the file name if needed
file_path = os.path.join(file_path, file_name)
with wave.open(file_path, 'wb') as wf:
wf.setnchannels(CHANNELS)
wf.setsampwidth(pyaudio.PyAudio().get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
if __name__ == "__main__":
target_directory = #give directory path
duration_seconds = 10 # Adjust the duration as needed
record_audio(target_directory, duration_seconds)
import whisper
model= whisper.load_model('base')
audio=whisper.load_audio(audio_file)