├── README.md
├── audiorecording.py
├── requirements.txt
├── speakwithchatGPT.py
└── testgpt.py
/README.md:
--------------------------------------------------------------------------------
1 | # Whisper-GPT
2 | This is a program built to build a closed loop where, user can chat with chatgpt using voice using OpenAI's whisper
3 |
4 | ## Setup:
5 |
6 | 1) use requirements.txt file to install dependencies
7 | 2) Enter your OpenAI credentials in `testgpt.py`
8 |
9 | 
10 |
11 | 3) ` Use the below steps `
12 | * First upgrade the revchat gpt
13 | `pip3 install revChatGPT==0.0.a42`
14 |
15 | * Then change the config as below to enter your session token
16 | - `This requires chrome browser`
17 | * Please find the detailed steps to obtain the tokens here
18 | - [Instructions](https://github.com/acheong08/ChatGPT/wiki/Setup)
19 |
20 |
21 |
22 | 
23 |
24 |
25 |
26 | ## Code Run:
27 | 1) Run the code from `speakwithchatGPT.py`
28 | 
29 | 2) Choose the option
30 | 
31 |
32 |
33 | ## To-Do's
34 | - [ ] Add option for T.T.S. probably pyttsx3
35 | - [ ] Create an executable file, for easy sharing
36 | - [ ] Take yes/no through voice for continued response
37 | - [ ] Clean up the codespace
38 |
39 | I would like to thank the brilliant work from OpenAI and also [acheong08](https://github.com/acheong08), without whose work this would have been impossible
40 | 1) [Whisper](https://github.com/openai/whisper)
41 | 2) [revChatGPT](https://github.com/acheong08/ChatGPT)
42 |
43 | ## Star History
44 |
45 | [](https://star-history.com/#rajuptvs/Whisper-GPT&Date)
46 |
47 |
48 |
--------------------------------------------------------------------------------
/audiorecording.py:
--------------------------------------------------------------------------------
1 |
2 | import tempfile
3 | import queue
4 | import sys
5 |
6 | import sounddevice as sd
7 | import soundfile as sf
8 | import numpy
9 | assert numpy
10 | def rec_audio(filename="audiorec_"):
11 | q = queue.Queue()
12 |
13 |
14 | def callback(indata, frames, time, status):
15 | """This is called (from a separate thread) for each audio block."""
16 | if status:
17 | print(status, file=sys.stderr)
18 | q.put(indata.copy())
19 |
20 | samplerate=None
21 | #filename=None
22 | device=None
23 | channels=1
24 | subtype=None
25 | try:
26 | if samplerate is None:
27 | device_info = sd.query_devices(device, 'input')
28 | # soundfile expects an int, sounddevice provides a float:
29 | samplerate = int(device_info['default_samplerate'])
30 | if filename is not None:
31 | filename = tempfile.mktemp(prefix=filename,
32 | suffix='.wav', dir='')
33 |
34 | # Make sure the file is opened before recording anything:
35 | with sf.SoundFile(filename, mode='x', samplerate=samplerate,
36 | channels=channels, subtype=subtype) as file:
37 | with sd.InputStream(samplerate=samplerate, device=device,
38 | channels=channels, callback=callback):
39 | print('#' * 50)
40 | print('press Ctrl+C to stop the recording')
41 | print('#' * 50)
42 | while True:
43 | file.write(q.get())
44 | except KeyboardInterrupt:
45 | print('\nRecording finished: ' + repr(filename))
46 |
47 | return filename
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | anyio==3.6.2
2 | certifi==2022.9.24
3 | cffi==1.15.1
4 | charset-normalizer==2.1.1
5 | colorama==0.4.6
6 | cssselect2==0.7.0
7 | ffmpeg-python==0.2.0
8 | filelock==3.8.2
9 | future==0.18.2
10 | h11==0.14.0
11 | h2==4.1.0
12 | hpack==4.0.0
13 | httpcore==0.16.2
14 | httpx==0.23.1
15 | huggingface-hub==0.11.1
16 | hyperframe==6.0.1
17 | idna==3.4
18 | lxml==4.9.1
19 | more-itertools==9.0.0
20 | numpy==1.23.5
21 | OpenAIAuth==0.0.6
22 | packaging==22.0
23 | Pillow==9.3.0
24 | pip==22.3.1
25 | pycparser==2.21
26 | PyYAML==6.0
27 | regex==2022.10.31
28 | reportlab==3.6.12
29 | requests==2.28.1
30 | revChatGPT==0.0.36.1
31 | rfc3986==1.5.0
32 | scipy==1.9.3
33 | setuptools==65.5.0
34 | six==1.16.0
35 | sniffio==1.3.0
36 | sounddevice==0.4.5
37 | soundfile==0.11.0
38 | svglib==1.4.1
39 | tinycss2==1.2.1
40 | tls-client==0.1.5
41 | tokenizers==0.13.2
42 | torch==1.13.0+cu116
43 | torchaudio==0.13.0+cu116
44 | torchvision==0.14.0+cu116
45 | tqdm==4.64.1
46 | transformers==4.25.1
47 | typing_extensions==4.4.0
48 | urllib3==1.26.13
49 | webencodings==0.5.1
50 | wheel==0.37.1
51 | whisper==1.0
52 | wincertstore==0.2
53 |
--------------------------------------------------------------------------------
/speakwithchatGPT.py:
--------------------------------------------------------------------------------
1 | import whisper
2 | import sounddevice as sd
3 | from scipy.io.wavfile import write
4 | import os
5 |
6 |
7 | import tempfile
8 | import queue
9 | import sys
10 | from testgpt import chatme
11 |
12 | import sounddevice as sd
13 | import soundfile as sf
14 | import numpy
15 | assert numpy
16 | from audiorecording import rec_audio
17 | class whisper_gpt:
18 | def __init__(self,model_size,file) :
19 | self.model_size=model_size
20 | self.file=file
21 | self.model = whisper.load_model(model_size)
22 |
23 |
24 | def transcribe(self):
25 | self.final = self.model.transcribe(self.file)
26 |
27 | def get_result(self):
28 | self.transription=self.final["text"]
29 | return self.transription
30 |
31 |
32 | choice = input("Enter your medium to chat with chatGPT \n 1: Chat with Voice \n 2: Chat with saved audio clip \n 3: Chat with text \n ")
33 | if choice == "1":
34 | decision=True
35 | while decision==True:
36 | audiofile=rec_audio("test")
37 | whispers = whisper_gpt("base",audiofile)
38 | whispers.transcribe()
39 | output=whispers.get_result()
40 | final_out=chatme(output)
41 | takeusr=input("Continue..... Y/N")
42 | if takeusr=="y":
43 | decision=True
44 | else:
45 | print("Nice Talking to you !!")
46 | decision=False
47 | elif choice =="2":
48 | print("You gotta select the first option!!!!")
49 | whispers = whisper_gpt("base","testy4pzkg2r.wav")
50 | whispers.transcribe()
51 | whispers.get_result()
52 | elif choice =="3":
53 | input_text=input("Enter the text... \n ")
54 | final_out=chatme(input_text)
55 |
56 |
--------------------------------------------------------------------------------
/testgpt.py:
--------------------------------------------------------------------------------
1 | from revChatGPT.revChatGPT import Chatbot
2 |
3 | def chatme(msg="Byeee"):
4 | config = {
5 | "email": "your_email_goes_here",
6 | "password": "your_passowrd_here"
7 | }
8 |
9 |
10 | chatbot = Chatbot(config, conversation_id=None)
11 |
12 | print("Input given is .....",msg)
13 | message = chatbot.get_chat_response(msg)['message']
14 | print(message)
15 | return message
16 |
--------------------------------------------------------------------------------