Android利用原生SpeechRecognizer识别语音

无聊的我又来写Android项目开发中遇到的问题了


首先奉上GitHub地址,以免浪费时间: https://github.com/Binoculus/Android-SpeechRecognition

在代码中,我的目标是识别使用软件的人读的内容是否正确,所以比较简单,这里我写死的一个读的内容

private String string = "what's your name";

没办法,我就会这一句,哈哈
在这里插入图片描述
好了,继续说

        final OpenJurisdiction openJurisdiction = new OpenJurisdiction();
        openJurisdiction.open(MainActivity.this);

这一段是我自己定义的一个工具类,用于开启各种权限

如果有其他需要也可自己在里面添加

因为高版本的Android需要动态开启权限,而我又比较懒,所以写了个工具类

在onResults与onPartialResults这两个方法,一个是返回识别完毕的,另一个是识别一段返回一段

emmmmmm程序员都是属鱼的,我也忘了哪个是哪个了,可以自己测试一下

bestResult就是识别到的文字,我自己测试的识别率还是比较高的,支持中英文,其他语言我不知道,毕竟我不会其他语言

最后有一个isNetworkAvailable方法是判断网络是否可用,因为这个语音识别是需要调用网络请求的

在bestResult刚get出来的时候,返回值是会带一个逗号,在这里,我用.substring(0,bestResult.length()-1);将最后的逗号去除了

如果对您有帮助,关注一下支持一下吧,谢谢您

QQ:1678949488

About Wouldn't your prefer to let your users speak instead of making them type? This plugin uses OS components for speech recognition and send it to your Unity scripts as String objects. Plugin supports: - Android >= 3.0 (haven’t tested below, it might work though… ), - iOS >= 10.0. That doesn’t mean you can’t target iOS lower than 10 - you simply have to prepare fallback code to cover cases when user doesn’t have access to speech recognition (SpeechRecognizer.EngineExists() for the help!). Keep in mind that both iOS and Android might use Internet connection for speech detection, which means it might fail in case there’s no active connection. Plugin doesn’t work in Editor! You have to run your app on real iOS or Android device. MOBILE SPEECH RECOGNIZER - UNITY PLUGIN ?2 Quick Start Open example scene Go to KKSpeechRecognizer/Example folder inside Unity and open ExampleScene: It shows basic usage of a plugin, which is: 1. Detecting if speech recognition exists on user’s device (keep in mind that it won’t be available on e.g. iOS 9 or old Android phones), 2. If it exists, and user clicks on “Start Recording” button it listens for recognized text and displays it on a screen, 3. On Android, speech recognition automatically detects when user finishes speaking, but on iOS we have to wait for user clicking “Stop Recording” to finish whole process (i.e. get final results). Before running it on Android or iOS device you have to… Setup permissions iOS After generating Xcode project (keep in mind that you have to use Xcode 8 or higher) you have to add two permissions keys to your project: MOBILE SPEECH RECOGNIZER - UNITY PLUGIN ?3 NSMicrophoneUsageDescription explanation from Apple docs: This key lets you describe the reason your app accesses any of the the device’s microphones. When the system prompts the user to allow access, this string is displayed as part of the alert. NSSpeechRecognitionUsageDescription explanation from Apple docs: This key lets you describe the reason y
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值