After successfully adding a basic play and stop functionality to the application, let's now access the hosted model to generate, fetch, and play a new audio file every time. The following steps discuss in detail how we can access the model inside the application:
- First of all, we define the fetchResponse() method to generate and fetch new audio files:
void fetchResponse() async { final response = await http.get('http://35.225.134.65:8000/generate'); if (response.statusCode == 200) { var v = json.decode(response.body); fileName = v["result"] ; } else { throw Exception('Failed to load'); } }
We begin by fetching the response from the API using http.get() and passing in the URL where the model is hosted. The response from ...