Initiate training externally

Hi everybody,

I have made a shopping list as skill. In the newer versions it comes with slot_programs for its parameters.

I’d like to be able to initiate training on the rhasspy master automatically. So the user is already in my config interface and I don’t want to ask him to visit the master webpage and click the button.

Is there a way to achieve that through an HTTP request somehow? I’ve tried to browse through the js sourcecode, but couldn’t really understand how that works.

I was hoping to find a simple URL or something like that which I could send a GET or POST to.

There is a topic: api/train on MQTT

Maybe that is what you need

Awesome, thank you!!

I don’t even have to use MQTT directly, there is an HTTP endpoint:

linux01:~# curl --data "" http://linux06:12101/api/train
Training completed in 64.18 second(s)linux01:~#

In case somebody else tries to do that as well - you have to send empty data to force POST.

GET does not work (like the documentation correctly suggests):

linux01:~# curl http://linux06:12101/api/train
MethodNotAllowed: MethodNotAllowed(405)linux01:~#

Thanks a lot for pointing me to the documentation!!!

I had really not assumed there was a published interface to do just that and simply hadn’t looked because of that.

Update:
If anyone wants to do it with PHP here’s a way to do it:

function triggerRhasspyTraining()
{
	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, Configuration::$rhasspyMasterUrl."/api/train");
	curl_setopt($ch, CURLOPT_POST, 1);
	//curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3");
	curl_setopt($ch, CURLOPT_POSTFIELDS, "");	// Send empty data to force POST

	// In real life you should use something like:
	// curl_setopt($ch, CURLOPT_POSTFIELDS, 
	//          http_build_query(array('postvar1' => 'value1')));

	// Receive server response ...
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	$server_output = curl_exec($ch);

	curl_close ($ch);

	// Further processing ...
	if (strpos($server_output, 'Training completed') !== false)
	{
		return true;
	}

	return false;
}
1 Like