科大讯飞官网:https://www.xfyun.cn/
首先登陆讯飞开放平台:https://passport.xfyun.cn/login,微信扫码关注登录

注册新账号

登陆后界面后,进入产品服务–>实时语音转写栏目


点击个人免费套餐,下面的立即领取,它会提醒我们去实名认证

实名认证一下

提交完认证之后

可以看到认证成功

回到平台领取界面,就可以领取了

点击右边的+号创建应用,很简单的,然后才能提交(不然会提示你还没有创建应用,不让提交)

确认下单


设置下支付密码

确认支付就好了


在控制台进入后有如下界面,点击语音听写,往下翻就可以找到Java MSC,点击下载就好了
红色箭头指向的是我们上一步创建的的项目名称



解压后目录如下:

在本地IDEA项目中使用的话,使用的是自己项目中下载的SDK包,和自己官网的Appid。否则SDK包和Appid不对应的话会报错

一定要使用自己官网的SDK和Appid对应,否则会出错10407】

VoiceSpeech类完整代码如下:【注意导入的各个包名】
package com.zhj.voice;
/**
* Topic
* Description
*
* @author zhouh
* @version 1.0
* Create by 2022/8/3 10:58
*/
import java.awt.Button;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import com.iflytek.cloud.speech.RecognizerListener;
import com.iflytek.cloud.speech.RecognizerResult;
import com.iflytek.cloud.speech.SpeechError;
import com.iflytek.cloud.speech.SpeechRecognizer;
import com.iflytek.cloud.speech.SpeechUtility;
import com.iflytek.util.DebugLog;
import com.iflytek.util.JsonParser;
import com.iflytek.util.Version;
public class VoiceSpeech extends Frame implements ActionListener {
Button startBtn;
Button stopBtn;
TextArea textArea;
// 语音听写对象
SpeechRecognizer speechRecognize;
private static final String DEF_FONT_NAME = "宋体";
private static final int DEF_FONT_STYLE = Font.BOLD;
private static final int DEF_FONT_SIZE = 30;
private static final int TEXT_COUNT = 100;
public VoiceSpeech() {
// 初始化听写对象
speechRecognize = SpeechRecognizer.createRecognizer();
// 设置组件
startBtn = new Button("start");
stopBtn = new Button("stop");
textArea = new TextArea();
Panel btnPanel = new Panel();
Panel textPanel = new Panel();
// Button startBtn = new Button("开始");
//添加监听器
startBtn.addActionListener(this);
stopBtn.addActionListener(this);
btnPanel.add(startBtn);
btnPanel.add(stopBtn);
textPanel.add(textArea);
add(btnPanel);
add(textPanel);
// 设置窗体
setLayout(new GridLayout(2, 1));
setSize(400, 300);
setTitle("语音识别");
setLocation(200, 200);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == startBtn) {
textArea.setText("*************你说的是:");
if (!speechRecognize.isListening())
speechRecognize.startListening(recognizerListener);
else
speechRecognize.stopListening();
} else if (e.getSource() == stopBtn) {
speechRecognize.stopListening();
}
}
/**
* 听写监听器
*/
private RecognizerListener recognizerListener = new RecognizerListener() {
public void onBeginOfSpeech() {
// DebugLog.Log( "onBeginOfSpeech enter" );
// ((JLabel) jbtnRecognizer.getComponent(0)).setText("听写中...");
// jbtnRecognizer.setEnabled(false);
}
public void onEndOfSpeech() {
DebugLog.Log("onEndOfSpeech enter");
}
/**
* 获取听写结果. 获取RecognizerResult类型的识别结果,并对结果进行累加,显示到Area里
*/
public void onResult(RecognizerResult results, boolean islast) {
DebugLog.Log("onResult enter");
// 如果要解析json结果,请考本项目示例的 com.iflytek.util.JsonParser类
String text =
JsonParser.parseIatResult(results.getResultString());
// String text = results.getResultString();
// JsonParser json = new JsonParser();
// String newTest = json.parseIatResult(text);
// textArea.setText(newTest);
textArea.append(text);
text = textArea.getText();
if (null != text) {
int n = text.length() / TEXT_COUNT + 1;
int fontSize = Math.max(10, DEF_FONT_SIZE - 2 * n);
DebugLog.Log("onResult new font size=" + fontSize);
int style = n > 1 ? Font.PLAIN : DEF_FONT_SIZE;
Font newFont = new Font(DEF_FONT_NAME, style, fontSize);
textArea.setFont(newFont);
}
if (islast) {
iatSpeechInitUI();
}
}
public void onVolumeChanged(int volume) {
DebugLog.Log("onVolumeChanged enter");
if (volume == 0)
volume = 1;
else if (volume >= 6)
volume = 6;
// labelWav.setIcon(new ImageIcon("res/mic_0" + volume + ".png"));
}
public void onError(SpeechError error) {
DebugLog.Log("onError enter");
if (null != error) {
DebugLog.Log("onError Code:" + error.getErrorCode());
textArea.setText(error.getErrorDescription(true));
iatSpeechInitUI();
}
}
public void onEvent(int eventType, int arg1, int agr2, String msg) {
DebugLog.Log("onEvent enter");
}
};
/**
* 听写结束,恢复初始状态
*/
public void iatSpeechInitUI() {
// labelWav.setIcon(new ImageIcon("res/mic_01.png"));
// jbtnRecognizer.setEnabled(true);
// ((JLabel) jbtnRecognizer.getComponent(0)).setText("开始听写");
}
public static void main(String[] args) {
// 初始化
StringBuffer param = new StringBuffer();
param.append( "appid=" + Version.getAppid() );
// param.append( ","+SpeechConstant.LIB_NAME_32+"=myMscName" );
SpeechUtility.createUtility( param.toString() );
VoiceSpeech t = new VoiceSpeech();
}
}
接着可能会有包名爆红,提醒我们导入Jar包
我们找到1.3中下载好的SDK文件夹下,进入下面的lib–>lib目录下,找到两个jar包。【注意,Java_iat1021_a8641a01 (1)是我下载的SDK解压后的名字】

然后将两个jar包导入到项目中:


点击ok发现com.iflytek.cloud.speech相关的不爆红了

但是com.iflytek.util相关的import仍然会爆红,所以我这里下一步是选择在com目录下手动新建iflytek.util包【使其能够手动导入】
但是com.iflytek.util相关的import仍然会爆红,所以我这里是选择在com目录下手动新建iflytek.util包【使其能够手动导入】
之后找到1.2步下载解压后的SDK文件夹中的sample

跟着目录找到sample–>src–>com–>iflytek–>util下的6个类

全选,复制粘贴到我们本地IDEA的对应包com.iflytek.util下
(这里包下Version类名中显示蓝色,是因为我已经上传到github上并且本地IDEA修改代码了,所以会显示蓝色)

这时候会发现不报错了,所有的import都正常显示了

修改com.iflytek.util.Version类中的getAppid方法返回值为我们科大讯飞官网中项目的Appid,因为返回String类型,记得Appid加双引号:
"自己的Appid号"

Appid号在1.4节的时候得到了:

在本地下载解压好的SDK问价夹中找到lib–>lib包下的这4个文件,Ctrl+A后,Ctrl+C全选复制

然后粘贴到本地IDEA的项目根目录下就好了


至此,项目搭建就完成了。
进入VoiceSpeech类中运行main函数就可以成功启动项目且不报错了:

运行后会弹出弹框,点击start说话就可以识别到了。

识别后想要再次说话识别,点击stop后再点击start就可以了
使用科大飞讯语音合成报 20021 引擎错误:原因和解决参考我的这一篇博客使用科大飞讯语音合成SDK报 20021 引擎错误于讯飞科大导入的10407问题:原因(没复制.so和.ddl文件)和解决办法参考我的这一篇博客关于讯飞科大语音识别SDK导入的10407问题总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/