在android穿戴动作中更改语音识别器的语言

时间:2016-05-12 17:17:03

标签: android localization wear-os voice-recognition

在我的Android应用程序中,我创建了一个带有磨损功能的通知,并添加了识别语音输入的动作并将语音文本发送到另一个活动。我的问题是它只是识别谷歌现在设置中选择的语言(英语),我想从波斯语中获得声音。这是我的代码:

RemoteInput remoteInput  = new RemoteInput.Builder("My_Const_String")
    .setLabel("label when you talk")
    .build();

Intent replayIntent = new Intent(context, MyTestActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, replayIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action action = new NotificationCompat.Action.Builder(
        R.drawable.ic_btn, "Label when confirm your talk", pendingIntent)
        .addRemoteInput(remoteInput)
        .build();

NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle("Title")
    .setContentText("Content text")
    .setSmallIcon(R.drawable.ic_stat_name)
    .setContentText("My text02");

NotificationCompat.WearableExtender extender =
        new NotificationCompat.WearableExtender();

extender.addAction(action);
builder.extend(extender);

NotificationManagerCompat mgr = NotificationManagerCompat.from(context);
int NotificatinId = 1;
mgr.notify(NotificatinId, builder.build());

此外,我不想强​​制用户手动更改谷歌的设置。我尝试添加额外的如下,但它没有奏效:

Intent i = new Intent();
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "fa_IR");
i.putExtra(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES, "fa_IR");
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "fa");
Bundle bundle = new Bundle();
bundle = i.getExtras();

RemoteInput remoteInput  = new RemoteInput.Builder("My_Const_String")
    .setLabel("label when you talk")
    .addExtras(bundle)
    .build();

1 个答案:

答案 0 :(得分:-2)

它适用于法语和俄语。我认为Persian现在不支持。看看"语音输入的语言"一部分。