Merge pull request #6 from shuto-cn/master

添加appkey配置功能
This commit is contained in:
shuto-fandd 2020-10-19 18:26:29 +08:00 committed by GitHub
commit aa84aa2e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 76 deletions

111
README.md
View File

@ -1,69 +1,42 @@
# 科大讯飞的语音听说读写的cordova插件
## 安装方法
下载插件与官方SDK,android与ios的SDK需要分别建立项目下载SDK
下载之后找到插件下
ios目录src/ios
android目录src/android/libs
然后将SDK目录下
ios SDKlib/iflyMSC.framework
android SDKlibs
分别替换插件的ios目录和android目录中的文件
将android SDK assets\iflytek目录中的文件替换插件中src/android/assets/iflytek路径下的文件
然后修改plugin.xml
搜索app_id将后面的值换成自己申请的appid
修改src/ios/CDVSpeech.m
搜索app_id将后面的值换成自己申请的appid
运行cordova plugin add [插件的绝对路径] 或者 提交后的 git 地址
## 调用方法
/** 开始录音 最大持续时间40秒
* @Param 成功callback
* @Param 失败callback
* @Param 是否显示录音画面
* @Param 是否显示标点
*
*/
xunfeiListenSpeaking.startListen(success, error, isShowDialog, isShowPunc);
// 停止录音
xunfeiListenSpeaking.stopListen();
/**
* 开始说话
* @Param 成功callback
* @Param 失败callback
* @Param 需要说出的信息
*/
xunfeiListenSpeaking.startSpeak(success, error, message);
// 停止说话
xunfeiListenSpeaking.stopSpeak();
// 暂停说话
xunfeiListenSpeaking.pauseSpeaking();
// 恢复说话
xunfeiListenSpeaking.resumeSpeaking();
# 科大讯飞的语音听说读写的cordova插件
## 安装方法
APP_KEY参数值为您在科大讯飞申请的appid
运行cordova plugin add https://gitee.com/shuto/cordova-plugin-IFlyspeech-master.git --variable APP_KEY=${APP_KEY}
## 调用方法
/** 开始录音 最大持续时间40秒
* @Param 成功callback
* @Param 失败callback
* @Param 是否显示录音画面
* @Param 是否显示标点
*
*/
xunfeiListenSpeaking.startListen(success, error, isShowDialog, isShowPunc);
// 停止录音
xunfeiListenSpeaking.stopListen();
/**
* 开始说话
* @Param 成功callback
* @Param 失败callback
* @Param 需要说出的信息
*/
xunfeiListenSpeaking.startSpeak(success, error, message);
// 停止说话
xunfeiListenSpeaking.stopSpeak();
// 暂停说话
xunfeiListenSpeaking.pauseSpeaking();
// 恢复说话
xunfeiListenSpeaking.resumeSpeaking();

View File

@ -3,6 +3,8 @@
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-xunfeiListenSpeaking</name>
<preference name="APP_KEY" />
<preference name="CHANNEL" default="developer-default" />
<engines>
<engine name="cordova" version=">=3.0" />
</engines>
@ -65,7 +67,7 @@
<source-file src="src/android/src/com/thomas/xunfeilistenspeaking/XunfeiDialogActivity.java" target-dir="src/com/thomas/xunfeilistenspeaking" />
<!-- res -->
<config-file target="res/values/strings.xml" parent="/resources">
<string name="app_id">5aace5bb</string>
<string name="app_id">$APP_KEY</string>
<string name="xunfei_cancel_listen">取消语音</string>
</config-file>
</platform>
@ -87,6 +89,7 @@
<header-file src="src/ios/CDVSpeech.h" />
<source-file src="src/ios/CDVSpeech.m" />
<resource-file src="src/ios/IFlySpeechConfig.plist" />
<framework src="AVFoundation.framework" />
<framework src="AddressBook.framework" />
@ -102,8 +105,9 @@
<framework src="CoreTelephony.framework" />
<framework src="CoreLocation.framework" />
<framework src="Contacts.framework" />
<framework src="src/ios/iflyMSC.framework" custom="true" />
<config-file target="*IFlySpeechConfig.plist" parent="AppKey">
<string>$APP_KEY</string>
</config-file>
</platform>
</plugin>

View File

@ -16,8 +16,6 @@
#define STR_RESULTS @"results"
#define STR_PROGRESS @"progress"
// always replace the appid and the SDK with what you get from voicecloud.cn
#define SPEECH_APP_ID @"5c32bdde"
@interface CDVSpeech()
@ -30,14 +28,25 @@
- (void)login:(CDVInvokedUrlCommand*)command
{
self.callbackId = command.callbackId;
self.appId = SPEECH_APP_ID;
if(self.appId == nil) {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"IFlySpeechConfig" ofType:@"plist"];
if (plistPath == nil) {
NSLog(@"error: IFlySpeechConfig.plist not found");
assert(0);
}
self.appId = [plistData valueForKey:@"AppKey"];
}
NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@",self.appId];
[IFlySpeechUtility createUtility:initString];
}
- (void) loadAppID{
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
}
#pragma mark -
- (void)startListening:(CDVInvokedUrlCommand*)command
{

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AppKey</key>
<string></string>
</dict>
</plist>