Я использую Google Actions Java SDK, чтобы написать приложение Google Assistant, и я хочу использовать немецкий язык для диалога. В действии. json Я установил локаль "de", которая, вероятно, должна сработать, но единственное, что меняется, - это Invocation Sentence, который читается на немецком языке, и как только ответ приложения считывается, голос меняется на engli sh one.
Я удалил все языковые настройки Engli sh в проекте, и язык разговора в консоли Google также немецкий. Использование локального de-DE в действии. json приводит к следующей ошибке:
Выбран языковой стандарт de-DE, но не выбран язык de.
{
"locale": "de",
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "conversation_1"
},
"intent": {
"name": "actions.intent.MAIN"
}
}
],
"conversations": {
"conversation_1": {
"name": "conversation_1",
"url": "fulfillment.url",
"fulfillmentApiVersion": 2
}
}
}
Следуя веб-крюку, который я получил от Пример приложения Google , но настроил его для собственного выполнения:
Сервел
@WebServlet(name = "actions", value = "/")
public class ActionsServlet extends HttpServlet {
private static final Logger LOG = LoggerFactory.getLogger(ActionsServlet.class);
private final App actionsApp = new NumberAction();
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
String body = req.getReader().lines().collect(Collectors.joining());
LOG.info("doPost, body = {}", body);
try {
String jsonResponse = actionsApp.handleRequest(body, getHeadersMap(req)).get();
LOG.info("Generated json = {}", jsonResponse);
res.setContentType("application/json");
res.setCharacterEncoding("UTF-8");
writeResponse(res, jsonResponse);
} catch (InterruptedException e) {
handleError(res, e);
} catch (ExecutionException e) {
handleError(res, e);
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/plain");
response
.getWriter()
.println("ActionsServlet is listening but requires valid POST request to respond with Action response.");
}
private void writeResponse(HttpServletResponse res, String asJson) {
try {
res.getWriter().write(asJson);
} catch (IOException e) {
e.printStackTrace();
}
}
private void handleError(HttpServletResponse res, Throwable throwable) {
try {
throwable.printStackTrace();
LOG.error("Error in App.handleRequest ", throwable);
res.getWriter().write("Error handling the intent - " + throwable.getMessage());
} catch (IOException e) {
e.printStackTrace();
}
}
private Map<String, String> getHeadersMap(HttpServletRequest request) {
Map<String, String> map = new HashMap();
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
map.put(key, value);
}
return map;
}
}
ActionSdkApp
public class NumberAction extends ActionsSdkApp {
private static final Logger LOGGER = LoggerFactory.getLogger(NumberAction.class);
@ForIntent("actions.intent.MAIN")
public ActionResponse welcome(ActionRequest request) {
LOGGER.info("Welcome intent start.");
ResponseBuilder responseBuilder = getResponseBuilder(request);
ResourceBundle rb = ResourceBundle.getBundle("resources", request.getLocale());
responseBuilder.add(rb.getString("welcome"));
responseBuilder.getConversationData().put("conversationToken", "Some Session");
LOGGER.info("Welcome intent end.");
return responseBuilder.build();
}
@ForIntent("actions.intent.TEXT")
public ActionResponse number(ActionRequest request) {
LOGGER.info("Number intent start.");
ResponseBuilder responseBuilder = getResponseBuilder(request);
ResourceBundle rb = ResourceBundle.getBundle("resources");
String convToken = (String) request.getConversationData().get("conversationToken");
String answer = NumberFulfillment.doFulfillment(request.getArgument("text").getTextValue(),Datastore.getInstance().getSession(convToken));
responseBuilder.add(answer);
LOGGER.info("Number intent end.");
return responseBuilder.build();
}
}