-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
openai.Audio is no longer supported when using recognize_whisper_api #720
Comments
Same issue, is there a way to use whisper with an |
I just use this with the OpenAI python package and just send the audio file to the whisper API that way: import time
import os
from pathlib import Path
from openai import OpenAI
import speech_recognition as sr
from pydub import AudioSegment
import dotenv
dotenv.load_dotenv()
import logging
# gets OPENAI_API_KEY from your environment variables
openai = OpenAI()
# Define the base path for audio files
audio_base_path = Path(__file__).parent.parent / "Assets/audio/"
def whisper(audio_file_name: str) -> None:
audio_file_path = audio_base_path / audio_file_name
# Create transcription from audio file
transcription = openai.audio.transcriptions.create(model="whisper-1", file=audio_file_path)
return transcription.text
def record_audio_sr():
logging.basicConfig(level=logging.INFO)
start = time.perf_counter()
recognizer = sr.Recognizer() # Initialize recognizer
recognizer.adjust_for_ambient_noise(source, duration=0.5) # Adjust for ambient noise and set a longer pause threshold
recognizer.energy_threshold = 300 # recognizer_instance.energy_threshold - Higher = less sensitive. default is 300. range is 50 - 4000
recognizer.pause_threshold = 1.0
#recognizer.dynamic_energy_threshold = True
#recognizer.dynamic_energy_adjustment_damping = 0.15
while True:
with sr.Microphone() as source:
print("Listening for audio...")
try:
audio = recognizer.listen(source, timeout=5.0, phrase_time_limit=10)
# Check if the detected audio is long enough (i.e., not just noise)
if len(audio.frame_data) / audio.sample_rate / audio.sample_width >= 2.5: # 0.5 seconds of speech
audio_file_name = "transcript.wav"
audio_file_path = audio_base_path / audio_file_name
with open(audio_file_path, "wb") as file:
file.write(audio.get_wav_data())
print(f"Recording saved as '{audio_file_path}'")
transcript = whisper(audio_file_name)
print(transcript)
end = time.perf_counter()
print(end - start)
else:
print("Detected audio too short, likely just noise.")
except sr.WaitTimeoutError:
print("No voice activity detected.")
break |
same issue here |
@Paracetamole1 @MiskaWasTaken See #729 (comment) You can copy the change to your local file, and have temp fix. |
Updated to the latest OpenAI API changes, and fixed #720
Thanks to reporting this and very sorry to my late response. Fixed at 3.10.2, thanks to @herrjemand |
From the official documentation examples folder
I get this error
The text was updated successfully, but these errors were encountered: