при преобразовании текста в аудио и последующей отправке в Google Ассистент pushtalk не дает точного результата. Поэтому мне нужно предложение, как я могу отправить текстовые данные в textinput помощника Google, чтобы получить более точный результат. Или любое другое предложение, которое может повысить мою точность в python
это то, что я сейчас установлен
"pip install --upgrade setuptools wheel \ google-assistant-library \ google-assistant-sdk [samples] \ google-auth-oauthlib [tool]"
это то, что я сейчас использую для преобразования текста в аудио, а затем отправки в Google-помощник
def post(self):
args = request.get_json()
text_received = str(args['assitant_text'])
file_name = str(args['google_file_name'])
project_id = str(args['project_id'])
device_model_id = str(args['device_model_id'])
refresh_token = str(args['refresh_token'])
client_id = str(args['client_id'])
client_secret = str(args['client_secret'])
voice = str(args['voice'])
text_received = "WHat is the capital of karnataka"
logger.emit("Received request parameters from api",
{
"api": "/google",
"args": args
}
)
token = {"refresh_token": refresh_token, "token_uri": "https://accounts.google.com/o/oauth2/token", "client_id": client_id, "client_secret": client_secret, "scopes": ["https://www.googleapis.com/auth/assistant-sdk-prototype"]}
with open('credentials.json', 'w') as outfile:
json.dump(token, outfile)
status = subprocess.call('aws polly synthesize-speech --output-format mp3 --voice-id %s --text "%s" %s.mp3' %(voice, text_received, file_name), shell=True, stdout=subprocess.PIPE)
logger.emit("Calling aws polly",
{
"api": "/google",
"status_code": status
}
)
tf = open("%s.mp3" % file_name, 'r')
_input = AudioSegment.from_file(tf.name)
tf = tempfile.NamedTemporaryFile(suffix=".wav", delete=True)
output = _input.set_channels(1).set_frame_rate(16000)
f = output.export(tf.name, format="wav")
status = subprocess.call('googlesamples-assistant-pushtotalk --credentials credentials.json --device-config device_config.json --project-id %s --device-model-id %s -i %s -o %s_output.wav' %(project_id, device_model_id, f.name, file_name), shell=True, stdout=subprocess.PIPE)
logger.emit("Calling google samples assistant pushtotalk",
{
"api": "/google",
"status": status
}
)
as_output = AudioSegment.from_file("%s_output.wav" %file_name)
kf = tempfile.NamedTemporaryFile(suffix=".wav")
output = as_output.set_channels(2)
f = output.export(kf.name, format="wav")
r = sr.Recognizer()
with sr.AudioFile(f.name) as source:
output_audio = r.record(source)
text = r.recognize_google(output_audio)
f.close()
kf.close()
os.remove("%s_output.wav" %file_name)
os.remove("%s.mp3" %file_name)
logger.emit("api completed successfully",
{
"api": "/google",
"status": "completed"
}
)
return jsonify({"response": text})