from pyChatGPT import ChatGPT import os session_token = os.environ.get('SessionToken') import whisper whisper_model = whisper.load_model("small") def chat_hf(audio, custom_token): try: whisper_text = translate(audio) api = ChatGPT(session_token) resp = api.send_message(whisper_text) api.refresh_auth() # refresh the authorization token api.reset_conversation() # reset the conversation gpt_response = resp['message'] except: whisper_text = translate(audio) api = ChatGPT(custom_token) resp = api.send_message(whisper_text) api.refresh_auth() # refresh the authorization token api.reset_conversation() # reset the conversation gpt_response = resp['message'] return whisper_text, gpt_response def translate(audio): print(""" — Sending audio to Whisper ... — """) audio = whisper.load_audio(audio) audio = whisper.pad_or_trim(audio) mel = whisper.log_mel_spectrogram(audio).to(whisper_model.device) _, probs = whisper_model.detect_language(mel) transcript_options = whisper.DecodingOptions(task="transcribe", fp16 = False) #translate_options = whisper.DecodingOptions(task="translate", fp16 = False) transcription = whisper.decode(whisper_model, mel, transcript_options) #translation = whisper.decode(whisper_model, mel, translate_options) print("language spoken: " + transcription.language) print("transcript: " + transcription.text) print("———————————————————————————————————————————") #print("translated: " + translation.text) return transcription.text title = """
Chat with GPT with your voice in your native language !
If it fails enter custom session key see video for reference refer
Bhavesh Baht video