ios - Cordova:有没有办法检测语音听写是否在 iOS 上结束

标签 ios cordova phonegap-plugins cordova-plugins hybrid-mobile-app

请注意,此问题适用于 Cordova/PhoneGap/Hybrid 应用。

我有一个 <textarea>为此,我希望应用程序仅在语音听写输入结束时以某种方式运行——即用户选项卡“完成”。然而,事实证明这是相当困难的。

iOS 的 UIKit提供 dictationRecordingDidEnd UITextInput 下的事件但我不确定这是否可以用于混合应用程序。 (iOS 开发者库文档 here)

编辑:我正在使用 ionic-plugin-keyboard .

任何想法将不胜感激。

最佳答案

或许您可以尝试使用 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 绑定(bind)到: stopListening();cancelListening(); 方法,具体取决于操作。

关于ios - Cordova:有没有办法检测语音听写是否在 iOS 上结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35211615/

相关文章:

cordova - Ionic-3 应用程序的生产构建失败

javascript - 命名回调函数不起作用

ios - PhoneGap 应用程序需要 native iOS 代码来提供后台服务吗?

iphone - 如何创建 iPhone 多品牌应用程序?

objective-c - 将 subview 添加到当前 View ,而不会弄乱 View 中对象的位置

ios - 如何获得默认的 iOS 红色警告颜色?

ios - 不规则字体名称何时与粗体和斜体结合使用?

android - 如何通过在android中使用phonegap api将.db文件从 Assets 文件夹复制到数据库文件夹来创建数据库

cordova-plugin-device 防止 deviceready 触发

javascript - 在inApp浏览器中注入(inject)代码并在应用程序中获取它的返回值