Cordova: 有没有一种方法可以检测iOS上语音识别是否已经结束?

7
请注意,此问题适用于 Cordova/PhoneGap/Hybrid 应用程序。
我有一个 <textarea>,当语音输入结束时,我希望应用程序只以某种方式运行 - 即用户选中“完成”。然而,这证明是相当困难的。
iOS 的 UIKitUITextInput 下提供了 dictationRecordingDidEnd 事件,但我不确定它是否可以在混合应用程序中使用。(iOS 开发者库文档 here
编辑:我正在使用 ionic-plugin-keyboard
任何想法将不胜感激。
1个回答

4
也许你可以尝试使用SpeechRecognitionPlugincordova-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绑定到:stopListening();cancelListening(); 方法,具体取决于所需的操作。


2
我也会推荐使用 cordova-plugin-iflyspeech 插件。 - Oscar Bout

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接