#import <Foundation/Foundation.h>
#import <Speech/Speech.h> @interface SpeechListener : NSObject
<SFSpeechRecognitionTaskDelegate,SFSpeechRecognizerDelegate> @property(nonatomic,strong)SFSpeechRecognizer *listener;
@property(nonatomic,strong)SFSpeechRecognitionTask *currentTask;
@property(nonatomic,assign)SFSpeechRecognizerAuthorizationStatus authorizationStatus;
@property(nonatomic,strong)SFSpeechAudioBufferRecognitionRequest *currentRequest;
@property(nonatomic,assign)BOOL inRecognizer;
@property(nonatomic,copy)void (^haveRecognizerSpeakTextBlock)(NSString *text,NSTimeInterval startLocation,NSTimeInterval length); -(void)startRecognizer;
-(void)giveBuffer:(CMSampleBufferRef)buffer;
-(void)endRecognizer; @end
#import "SpeechListener.h"

@interface SpeechListener()

@property(nonatomic,copy)NSString *currentText;
@property(nonatomic,assign)NSTimeInterval beginListenLocation; @end @implementation SpeechListener -(instancetype)init
{
self = [super init];
if (self) {
self.listener = [[SFSpeechRecognizer alloc] initWithLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];
[self.listener setDelegate:self];
[self requestAuthorizationStatus];
}
return self;
} -(void)requestAuthorizationStatus
{
typeof(self) __weak weakself = self;
[SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
typeof(weakself) __strong strongself = weakself;
strongself.authorizationStatus = status;
}];
} -(void)startRecognizer
{
self.beginListenLocation = CFAbsoluteTimeGetCurrent();
self.currentRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
[self.currentRequest setShouldReportPartialResults:YES];
typeof(self) __weak weakself = self;
self.currentTask = [self.listener recognitionTaskWithRequest:self.currentRequest resultHandler:^(SFSpeechRecognitionResult *result, NSError *error) {
typeof(weakself) __strong strongself = weakself;
if (strongself.inRecognizer) {
if (error != nil) {
[strongself endRecognizer];
}
else
if(result != nil) {
if (strongself.inRecognizer) {
strongself.currentText = [[result bestTranscription] formattedString];
}
if ([result isFinal]) {
[strongself endRecognizer];
}
}
}
if (error) { }
}];
self.inRecognizer = YES;
} -(void)endRecognizer
{
if (self.currentText.length > ) {
if (self.haveRecognizerSpeakTextBlock) {
self.haveRecognizerSpeakTextBlock(self.currentText, self.beginListenLocation, CFAbsoluteTimeGetCurrent() - self.beginListenLocation);
}
} self.inRecognizer = NO;
if (self.currentTask) {
[self.currentTask cancel];
self.currentTask = nil;
}
if (self.currentRequest) {
[self.currentRequest endAudio];
self.currentRequest = nil;
}
self.currentText = @"";
} -(void)speechRecognizer:(SFSpeechRecognizer *)speechRecognizer availabilityDidChange:(BOOL)available
{
self.inRecognizer = !available;
} -(void)giveBuffer:(CMSampleBufferRef)buffer
{
if (self.currentRequest) {
[self.currentRequest appendAudioSampleBuffer:buffer];
}
if (self.inRecognizer && (CFAbsoluteTimeGetCurrent() - self.beginListenLocation) > ) {
[self endRecognizer];
[self startRecognizer];
}
} @end

https://www.politepix.com/openears/   一款免费的识别工具

iOS10原生的语音转文字功能的更多相关文章

  1. iOS 10中如何搭建一个语音转文字框架

    在2016WWDC大会上,Apple公司介绍了一个很好的语音识别的API,那就是Speech framework.事实上,这个Speech Kit就是Siri用来做语音识别的框架.如今已经有一些可用的 ...

  2. 语音识别系统:有免费实用的"语音到文字"的软件么?

    自从看了<李开复自传>,就对"语音识别系统"产生了非常深刻的印象. 根据自己的判断,语音识别系统还是非常有用的. 以自己的实际需求来看: 1.中国象棋中的应用. 中国象 ...

  3. 原生JS实现购物车结算功能代码+zepto版

    html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  4. android中自定义view---实现竖直方向的文字功能,文字方向朝上,同时提供接口,判断当前touch的是哪个字符,并改变颜色

    android自定义view,实现竖直方向的文字功能,文字方向朝上,同时提供接口,判断当前touch的是哪个字符,并改变颜色. 由于时间比较仓促,因此没有对代码进行过多的优化,功能远远不如androi ...

  5. C# 语音识别(文字to语音、语音to文字)

    最近打算研究一下语音识别,但是发现网上很少有C#的完整代码,就把自己的学习心得放上来,和大家分享一下. 下载API: 1)SpeechSDK51.exe                   (67.0 ...

  6. 机器人之路的第一小步:录音+语音识别(语音转文字),大小600K(免费下载)!

    机器人之路的第一小步:录音+语音识别(语音转文字),大小600K,本人出品! 机器人之路的第一小步:录音+语音识别,准确率还不是特别高,不过普通话标准的话,识别准确率还是不错的,大家可以体验一下,请下 ...

  7. iOS语音播报文字

    记得大学的时候学微软Window Phone时,有语音识别类似苹果的嘿,Siri.今天无聊百度搜了一下,搜到苹果语音播报文字.自己试了下还挺好玩. 1.引入框架#import <AVFounda ...

  8. Python使用websocket调用语音识别,语音转文字

    @ 目录 0. 太长不看系列,直接使用 1. Python调用标贝科技语音识别websocket接口,实现语音转文字 1.1 环境准备: 1.2 获取权限 1.2.1 登录 1.2.2 创建新应用 1 ...

  9. 手把手使用Python语音识别,进行语音转文字

    0. 太长不看系列,直接使用 在1.2官网注册后拿到APISecret和APIKey,直接复制文章2.4demo代码,确定音频为wav格式,采样率为16K,在命令行执行 python single_s ...

随机推荐

  1. 4.翻译系列:EF 6 Code-First默认约定(EF 6 Code-First系列)

    原文地址:http://www.entityframeworktutorial.net/code-first/code-first-conventions.aspx EF 6 Code-First系列 ...

  2. 三星S4 i9508 4.4.2 root 教程

    现在有很多一键root的软件,但是各怀鬼胎,最好不用. 最近玩腻了三方的rom,刷回了官方的rom,顿时更稳定了,以外的是这个版本的导航被切了,拍手叫好啊.输入法引入了搜狗的云输入,更方便了,官方的输 ...

  3. 腾讯云SpringBoot部署 + HTTPS配置

    springboot可以打包为jar和war,jar不多说了,最近的一个工程需要打包为war发布,大致说一下吧: 先看一下项目的大致结构: 第一步,需要排除springboot自带的tomcat插件 ...

  4. JsonCpp 的使用

    JSON全称为JavaScript ObjectNotation,它是一种轻量级的数据交换格式,易于阅读.编写.解析.jsoncpp是c++解析JSON串常用的解析库之一. jsoncpp中主要的类: ...

  5. linux每日命令(38):iostat命令

    Linux系统中的 iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况.同 ...

  6. 图像处理滤波应用(Halcon)

    1.增强对比度:halcon算子 equ_histo_image (GrayImage, ImageEquHisto) 2.空间滤波基础 滤波指接受或拒绝一定的频率分量.低通滤波器的最终效果是模糊(平 ...

  7. WebRTC 零基础开发者教程(中文版)下载

    WebRTC 简介 WebRTC,是一个支持网页浏览器进行实时语音通话或视频聊天的技术,是谷歌2010年以6820万美元收购Global IP Solutions公司而获得的一项技术. WebRTC提 ...

  8. svn-checkout后,循环遍历查找包含某字符串的文件

    这里涉及几个知识点: 1.安装subversion,不多说了,网上有教程 2.循环遍历所有目录层级,找相 关文件 #!/bin/bash #########svn checkout项目出来 svn_d ...

  9. RMAN正确地删除Archivelog以及设置有备库的归档删除策略

    原文链接:http://blog.sina.com.cn/s/blog_64e166580100xks5.html 如何正确地删除Archivelog: Archivelog并不能直接得从OS层直接物 ...

  10. Unity UI相关总结

    UIGrid 加载面板时,如果面板中含有大容量的 UIGrid,可能会很卡.我们可以只加载 UIGrid 的前 n 个单元格对象,在显示面板之后,利用协程加载剩余的所有单元格,每帧加载 m 个. 同样 ...