开车时将通知转为文字转语音
Turning notifications to text-to-speech when driving
我有一个应用程序,根据某些事件,将正常通知更改为文本到语音,因为有时 phone 对用户不可用,这样会更安全处理 phone.
例如,当你在开车时,这很危险,所以我想将通知转为文字转语音。
我已经找了很长时间关于在开车时将文字转为语音的解释,但我在任何地方都找不到任何参考资料。
为了生成文本到语音,我有这部分,效果很好:
private TextToSpeech mTextToSpeech;
public void sayText(Context context, final String message) {
mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
try {
if (mTextToSpeech != null && status == TextToSpeech.SUCCESS) {
mTextToSpeech.setLanguage(Locale.US);
mTextToSpeech.speak(message, TextToSpeech.QUEUE_ADD, null);
}
} catch (Exception ex) {
System.out.print("Error handling TextToSpeech GCM notification " + ex.getMessage());
}
}
});
}
但是,我不知道如何检查我是否正在开车。
要知道您是否在开车,您可以使用 Activity Recognition API
这是一个很棒的教程,可能会对您有所帮助Tutorial and Source Code
- 因为 Ashwin suggested, you can use Activity recognition Api, but there's a downside of that, the driving samples you'll receive, has a field of 'confidence' 这并不总是准确的,所以您必须做额外的工作(例如检查位置以查看您是否真的搬家)才能完全了解用户是否搬家。
- 您可以使用 google 的 FenceApi which allows you to define a fence of actions such as driving, walking, running, etc.
This api launched recently. If you want a sample for using it, you can use this answer。
- 您可以使用此 git project(一切免费),它完全符合您的要求:在您开车时向普通通知添加文字转语音。
我有一个应用程序,根据某些事件,将正常通知更改为文本到语音,因为有时 phone 对用户不可用,这样会更安全处理 phone.
例如,当你在开车时,这很危险,所以我想将通知转为文字转语音。 我已经找了很长时间关于在开车时将文字转为语音的解释,但我在任何地方都找不到任何参考资料。
为了生成文本到语音,我有这部分,效果很好:
private TextToSpeech mTextToSpeech;
public void sayText(Context context, final String message) {
mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
try {
if (mTextToSpeech != null && status == TextToSpeech.SUCCESS) {
mTextToSpeech.setLanguage(Locale.US);
mTextToSpeech.speak(message, TextToSpeech.QUEUE_ADD, null);
}
} catch (Exception ex) {
System.out.print("Error handling TextToSpeech GCM notification " + ex.getMessage());
}
}
});
}
但是,我不知道如何检查我是否正在开车。
要知道您是否在开车,您可以使用 Activity Recognition API
这是一个很棒的教程,可能会对您有所帮助Tutorial and Source Code
- 因为 Ashwin suggested, you can use Activity recognition Api, but there's a downside of that, the driving samples you'll receive, has a field of 'confidence' 这并不总是准确的,所以您必须做额外的工作(例如检查位置以查看您是否真的搬家)才能完全了解用户是否搬家。
- 您可以使用 google 的 FenceApi which allows you to define a fence of actions such as driving, walking, running, etc.
This api launched recently. If you want a sample for using it, you can use this answer。 - 您可以使用此 git project(一切免费),它完全符合您的要求:在您开车时向普通通知添加文字转语音。