Hi
I am trying to use Speech to Text from within Unity to send the resulting text to a python file which will send to GPT3 and retrieve results.
I have the Speech to Text working and the python code which connects to GPT3 API but I am not sure how to link the two.
Can I embed the python code inside unity or do I need to host externally and somehow trigger from unity? What is the best (least lag) approach and how do I do it?
If you just need to contact some API over the web, just do it directly with UnityWebRequest
If you absolutely must, you can integrate Python in Unity but it is a LOT of extra work. You can also get asset store packages that get you so much of the way there Python-wise.
thanks for the tip - if UnityWebRequest can support this then life becomes much easier. This is python code.
import os
import openai
def open_file(filepath):
with open (filepath, 'r', encoding='utf-8') as infile:
return infile.read()
def save_file(filepath, content):
with open (filepath, 'w', encoding='utf-8') as outfile:
outfile.write(content)
openai.api_key = open_file('openapikey.txt')
def gpt3 (prompt):
response = openai.Completion.create(
model = "text-curie-001",
prompt = prompt,
temperature = 1.0,
max_tokens = 500,
top_p = 1,
frequency_penalty = 0,
presence_penalty = 0
)
text = response['choices'][0]['text'].strip()
return text
prompt = open_file('prompt.txt')
prose = gpt3(prompt)
quesandanswer = prompt + prose
print ('\n\nQuestions:', prompt, prose)
save_file('questions.txt', prose)
prompt2 = open_file(prompt2.txt)
I want to replace the prompts so it is really just passing the text generated by the STT in unity that I need to worry about, and then how to retreive the result
The plugin for unity that i found seemed to suggest that I need to go via python. I did look at options in the assetstore but couldn’t find anything specifically for Speech to Text which is what I need