1111 get_type_hints ,
1212)
1313from pydantic import BaseModel
14- from pydub import AudioSegment
1514from datetime import datetime
1615from enum import Enum
1716import tiktoken
2423import time
2524import json
2625import os
26+ try :
2727
28+ from pydub import AudioSegment
29+ except :
30+ pass
2831
2932class ChatCompletions (BaseModel ):
3033 model : str = "gpt4free" # This is the agent name
@@ -1517,9 +1520,12 @@ async def chat_completions(
15171520 with open (audio_url , "wb" ) as f :
15181521 f .write (audio_data )
15191522 wav_file = f"./WORKSPACE/{ uuid .uuid4 ().hex } .wav"
1520- AudioSegment .from_file (audio_url ).set_frame_rate (16000 ).export (
1523+ try :
1524+ AudioSegment .from_file (audio_url ).set_frame_rate (16000 ).export (
15211525 wav_file , format = "wav"
15221526 )
1527+ except :
1528+ pass
15231529 # Switch this to use the endpoint
15241530 openai .api_key = (
15251531 self .headers ["Authorization" ]
@@ -1532,10 +1538,13 @@ async def chat_completions(
15321538 message = f"[ACTIVITY] Transcribing audio to text." ,
15331539 conversation_name = conversation_name ,
15341540 )
1535- with open (wav_file , "rb" ) as audio_file :
1536- transcription = openai .audio .transcriptions .create (
1537- model = agent_name , file = audio_file
1541+ try :
1542+ with open (wav_file , "rb" ) as audio_file :
1543+ transcription = openai .audio .transcriptions .create (
1544+ model = agent_name , file = audio_file
15381545 )
1546+ except :
1547+ pass
15391548 new_prompt += transcription .text
15401549 if "video_url" in msg :
15411550 video_url = str (
0 commit comments