添加appkey配置功能

This commit is contained in:
zher52 2020-10-19 16:24:36 +08:00
parent 9bb736e744
commit 18cc26ec62
4 changed files with 35 additions and 43 deletions

View File

@ -2,40 +2,10 @@
## 安装方法
下载插件与官方SDK,android与ios的SDK需要分别建立项目下载SDK
APP_KEY参数值为您在科大讯飞申请的appid
下载之后找到插件下
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
搜索appkey将后面的值换成自己申请的appid
修改res/values/strings.xml
搜索appid将后面的值换成自己申请的appid
修改src/ios/CDVSpeech.m
搜索app_id将后面的值换成自己申请的appid
运行cordova plugin add [插件的绝对路径]
运行cordova plugin add https://gitee.com/shuto/cordova-plugin-IFlyspeech-master.git --variable APP_KEY=${APP_KEY}
## 调用方法

View File

@ -1,7 +1,8 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-xunfeiListenSpeaking" version="0.0.1" 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" />
<platform name = "android">
<js-module name="xunfeiListenSpeaking" src="www/cordova-plugin-xunfeiListenSpeaking.js">
<clobbers target="xunfeiListenSpeaking" />
@ -28,10 +29,10 @@
<!-- 移动统计分析 -->
<meta-data
android:name="IFLYTEK_APPKEY"
android:value="'5b553cd9'" />
android:value="$APP_KEY" />
<meta-data
android:name="IFLYTEK_CHANNEL"
android:value="Android_Demo" />
android:value="$CHANNEL" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
@ -82,7 +83,7 @@
<config-file target="res/values/strings.xml" parent="/resources">
<!--<string name="app_name">讯飞语音示例</string>-->
<!-- 请替换成在语音云官网申请的appid -->
<string name="app_id">584e7225</string>
<string name="app_id">$APP_KEY</string>
<string name="example_explain">本示例为讯飞语音Android平台开发者提供语音听写、语法识别、语义理解和语音合成等代码样例旨在让用户能够依据该示例快速开发出基于语音接口的应用程序。</string>
<string name="text_tts_source">科大讯飞作为中国最大的智能语音技术提供商在智能语音技术领域有着长期的研究积累并在中文语音合成、语音识别、口语评测等多项技术上拥有国际领先的成果。科大讯飞是我国唯一以语音技术为产业化方向的“国家863计划成果产业化基地”…</string>
<string name="text_tts_source_en">iFLYTEK is a national key software enterprise dedicated to the research of intelligent speech and language technologies, development of software and chip products, provision of speech information services, and integration of E-government systems. The intelligent speech technology of iFLYTEK, the core technology of the company, represents the top level in the world.</string>
@ -246,7 +247,7 @@
<param name="ios-package" value="CDVSpeech" />
</feature>
</config-file>
<resource-file src="src/ios/IFlySpeechConfig.plist" />
<config-file target="*-Info.plist" parent="NSMicrophoneUsageDescription">
<string></string>
</config-file>
@ -267,9 +268,11 @@
<framework src="Foundation.framework" />
<framework src="CoreTelephony.framework" />
<framework src="CoreLocation.framework" />
<framework src="Contacts.framework" />
<framework src="src/ios/iflyMSC.framework" custom="true" />
<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

@ -17,7 +17,7 @@
#define STR_PROGRESS @"progress"
// always replace the appid and the SDK with what you get from voicecloud.cn
#define SPEECH_APP_ID @"589d270d"
// static SPEECH_APP_ID;
@interface CDVSpeech()
@ -30,14 +30,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>