请注意,此问题适用于 Cordova/PhoneGap/Hybrid 应用。
我有一个 <textarea>
为此,我希望应用程序仅在语音听写输入结束时以某种方式运行——即用户选项卡“完成”。然而,事实证明这是相当困难的。
iOS 的 UIKit
提供 dictationRecordingDidEnd
UITextInput
下的事件但我不确定这是否可以用于混合应用程序。 (iOS 开发者库文档 here)
编辑:我正在使用 ionic-plugin-keyboard
.
任何想法将不胜感激。
最佳答案
或许您可以尝试使用 SpeechRecognitionPlugin或 cordova-plugin-iflyspeech
对于 cordova-plugin-iflyspeech
,您有 13 个事件来控制 iOS 设备中的语音控制,例如:
SpeechBegin
SpeechEnd
SpeechCancel
SpeechResults
SpeechError
VolumeChanged
SpeakBegin
SpeakPaused
SpeakResumed
SpeakCancel
SpeakCompleted
SpeakProgress
BufferProgress
并且支持大量语言,例如:英语(美国)、英语(英国)、法语、西类牙语、意大利语等。
这是文档的一个例子
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
$('div#status').html( 'speech engine ready' );
}
function startReading() {
var text = $('textarea#read').val();
navigator.speech.startSpeaking( text, {voice_name: 'xiaoyan'} );
}
function stopReading() {
navigator.speech.stopSpeaking();
}
function startListening() {
$('div#status').html( 'Listening, please speak.' );
navigator.speech.startListening({language:'en-US'} function(str) {
// this is what the device hear and understand
$('textarea#read').val( str );
});
}
function stopListening() {
navigator.speech.stopListening();
}
在这里您可以将 iOS 方法 dictationRecordingDidEnd
绑定(bind)到:
stopListening();
或 cancelListening();
方法,具体取决于操作。
关于ios - Cordova:有没有办法检测语音听写是否在 iOS 上结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35211615/