gpt4 book ai didi

java - Google助理只能用英语回答,但永远不会

转载 作者:行者123 更新时间:2023-12-01 17:27:37 25 4
gpt4 key购买 nike

我正在使用Google Actions Java SDK编写Google Assistant应用,并且想在对话中使用德语。在action.json中,我设置了语言环境“ de”,这应该可以解决问题,但唯一改变的是调用语句,该语句将用德语读出,并且一旦应用程序响应被读出,语音就会变为英语之一。

我已经删除了项目中的所有英语语言设置,并且Google控制台的对话语言也是德语。在action.json中使用本地de-DE会导致以下错误:


选择了语言环境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 Example App获得的webhook,但根据自己的需要对其进行了定制:

塞尔维尔特

@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();
}
}

最佳答案

不同的Google Actions项目中的相同代码可以正常工作。

关于java - Google助理只能用英语回答,但永远不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61187610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com