-
Notifications
You must be signed in to change notification settings - Fork 0
/
Türkçe ses tanıma ile çalışan ChatGPT prompter.py
49 lines (39 loc) · 1.36 KB
/
Türkçe ses tanıma ile çalışan ChatGPT prompter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import time
import pyaudio
import speech_recognition as sr
import playsound
from gtts import gTTS
import openai
import uuid
api_key = "Buraya API anahtarını gir"
lang = 'tr'
openai.api_key = api_key
guy = ""
while True:
def get_adio():
r = sr.Recognizer()
with sr.Microphone(device_index=1) as source:
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio)
print(said)
global guy
guy = said
if "Buraya yapay zekanın adını gir" in said:
new_string = said.replace("Buraya yapay zekanın adını gir", "")
new_string = new_string.strip()
print(new_string)
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": new_string}])
text = completion.choices[0].message.content
speech = gTTS(text=text, lang=lang, slow=False, tld="com.tr")
file_name = f"welcome_{str(uuid.uuid4())}.mp3"
speech.save(file_name)
playsound.playsound(file_name, block=False)
except Exception as e:
print(f"Hata: {str(e)}")
return said
if "Dur" in guy:
break
get_adio()