├── .gitignore ├── .npmignore ├── Example ├── .buckconfig ├── .flowconfig ├── .gitignore ├── .watchmanconfig ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── keystores │ │ ├── BUCK │ │ └── debug.keystore.properties │ └── settings.gradle ├── index.android.js ├── index.ios.js ├── ios │ ├── Example.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Example.xcscheme │ ├── Example │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ │ └── LaunchScreen.xib │ │ ├── Images.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Info.plist │ │ └── main.m │ └── ExampleTests │ │ ├── ExampleTests.m │ │ └── Info.plist └── package.json ├── Readme.md ├── doc ├── 百度语音开放平台-iOS-SDK文档.md └── 百度语音开放平台-iOS-SDK文档.pdf ├── index.js ├── ios ├── BaiduVoiceSDK │ ├── BDSClientHeaders │ │ ├── ASR │ │ │ ├── .gitIgnore │ │ │ ├── BDSASRDefines.h │ │ │ ├── BDSASRParameters.h │ │ │ ├── BDSEventManager.h │ │ │ ├── BDSUploaderDefines.h │ │ │ ├── BDSUploaderParameters.h │ │ │ ├── BDSWakeupDefines.h │ │ │ ├── BDSWakeupParameters.h │ │ │ └── UIHeaders │ │ │ │ ├── BDRecognizerViewController.h │ │ │ │ ├── BDRecognizerViewDelegate.h │ │ │ │ ├── BDRecognizerViewParamsObject.h │ │ │ │ └── BDTheme.h │ │ └── TTS │ │ │ ├── BDSBuiltInPlayer.h │ │ │ ├── BDSMixedModeSynthesizer.h │ │ │ ├── BDSSpeechSynthesizer.h │ │ │ ├── BDSSpeechSynthesizerDelegate.h │ │ │ ├── BDSSpeechSynthesizerErrors.h │ │ │ ├── BDSSpeechSynthesizerParams.h │ │ │ └── BDSSynthesizerLogLevel.h │ └── BDSClientLib │ │ └── libBaiduSpeechSDK.a ├── ReactNativeBaiduVoiceRecognition.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── leon.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── leon.xcuserdatad │ │ └── xcschemes │ │ ├── ReactNativeBaiduVoiceRecognizition.xcscheme │ │ └── xcschememanagement.plist └── ReactNativeBaiduVoiceRecognizition │ ├── ReactNativeBaiduVoiceRecognition.h │ └── ReactNativeBaiduVoiceRecognition.m └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | Example 2 | doc 3 | -------------------------------------------------------------------------------- /Example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /Example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | # We fork some components by platform. 4 | .*/*.android.js 5 | 6 | # Ignore templates with `@flow` in header 7 | .*/local-cli/generator.* 8 | 9 | # Ignore malformed json 10 | .*/node_modules/y18n/test/.*\.json 11 | 12 | [include] 13 | 14 | [libs] 15 | node_modules/react-native/Libraries/react-native/react-native-interface.js 16 | node_modules/react-native/flow 17 | flow/ 18 | 19 | [options] 20 | module.system=haste 21 | 22 | esproposal.class_static_fields=enable 23 | esproposal.class_instance_fields=enable 24 | 25 | experimental.strict_type_args=true 26 | 27 | munge_underscores=true 28 | 29 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' 30 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 31 | 32 | suppress_type=$FlowIssue 33 | suppress_type=$FlowFixMe 34 | suppress_type=$FixMe 35 | 36 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-7]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 37 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-7]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 38 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 39 | 40 | [version] 41 | ^0.27.0 42 | -------------------------------------------------------------------------------- /Example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IJ 26 | # 27 | *.iml 28 | .idea 29 | .gradle 30 | local.properties 31 | 32 | # node.js 33 | # 34 | node_modules/ 35 | npm-debug.log 36 | 37 | # BUCK 38 | buck-out/ 39 | \.buckd/ 40 | android/app/libs 41 | android/keystores/debug.keystore 42 | -------------------------------------------------------------------------------- /Example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Example/android/app/BUCK: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # To learn about Buck see [Docs](https://buckbuild.com/). 4 | # To run your application with Buck: 5 | # - install Buck 6 | # - `npm start` - to start the packager 7 | # - `cd android` 8 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US` 9 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 10 | # - `buck install -r android/app` - compile, install and run application 11 | # 12 | 13 | lib_deps = [] 14 | for jarfile in glob(['libs/*.jar']): 15 | name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile) 16 | lib_deps.append(':' + name) 17 | prebuilt_jar( 18 | name = name, 19 | binary_jar = jarfile, 20 | ) 21 | 22 | for aarfile in glob(['libs/*.aar']): 23 | name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile) 24 | lib_deps.append(':' + name) 25 | android_prebuilt_aar( 26 | name = name, 27 | aar = aarfile, 28 | ) 29 | 30 | android_library( 31 | name = 'all-libs', 32 | exported_deps = lib_deps 33 | ) 34 | 35 | android_library( 36 | name = 'app-code', 37 | srcs = glob([ 38 | 'src/main/java/**/*.java', 39 | ]), 40 | deps = [ 41 | ':all-libs', 42 | ':build_config', 43 | ':res', 44 | ], 45 | ) 46 | 47 | android_build_config( 48 | name = 'build_config', 49 | package = 'com.example', 50 | ) 51 | 52 | android_resource( 53 | name = 'res', 54 | res = 'src/main/res', 55 | package = 'com.example', 56 | ) 57 | 58 | android_binary( 59 | name = 'app', 60 | package_type = 'debug', 61 | manifest = 'src/main/AndroidManifest.xml', 62 | keystore = '//android/keystores:debug', 63 | deps = [ 64 | ':app-code', 65 | ], 66 | ) 67 | -------------------------------------------------------------------------------- /Example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // whether to bundle JS and assets in debug mode 22 | * bundleInDebug: false, 23 | * 24 | * // whether to bundle JS and assets in release mode 25 | * bundleInRelease: true, 26 | * 27 | * // whether to bundle JS and assets in another build variant (if configured). 28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 29 | * // The configuration property can be in the following formats 30 | * // 'bundleIn${productFlavor}${buildType}' 31 | * // 'bundleIn${buildType}' 32 | * // bundleInFreeDebug: true, 33 | * // bundleInPaidRelease: true, 34 | * // bundleInBeta: true, 35 | * 36 | * // the root of your project, i.e. where "package.json" lives 37 | * root: "../../", 38 | * 39 | * // where to put the JS bundle asset in debug mode 40 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 41 | * 42 | * // where to put the JS bundle asset in release mode 43 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 44 | * 45 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 46 | * // require('./image.png')), in debug mode 47 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 48 | * 49 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 50 | * // require('./image.png')), in release mode 51 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 52 | * 53 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 54 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 55 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 56 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 57 | * // for example, you might want to remove it from here. 58 | * inputExcludes: ["android/**", "ios/**"], 59 | * 60 | * // override which node gets called and with what additional arguments 61 | * nodeExecutableAndArgs: ["node"] 62 | * 63 | * // supply additional arguments to the packager 64 | * extraPackagerArgs: [] 65 | * ] 66 | */ 67 | 68 | apply from: "../../node_modules/react-native/react.gradle" 69 | 70 | /** 71 | * Set this to true to create two separate APKs instead of one: 72 | * - An APK that only works on ARM devices 73 | * - An APK that only works on x86 devices 74 | * The advantage is the size of the APK is reduced by about 4MB. 75 | * Upload all the APKs to the Play Store and people will download 76 | * the correct one based on the CPU architecture of their device. 77 | */ 78 | def enableSeparateBuildPerCPUArchitecture = false 79 | 80 | /** 81 | * Run Proguard to shrink the Java bytecode in release builds. 82 | */ 83 | def enableProguardInReleaseBuilds = false 84 | 85 | android { 86 | compileSdkVersion 23 87 | buildToolsVersion "23.0.1" 88 | 89 | defaultConfig { 90 | applicationId "com.example" 91 | minSdkVersion 16 92 | targetSdkVersion 22 93 | versionCode 1 94 | versionName "1.0" 95 | ndk { 96 | abiFilters "armeabi-v7a", "x86" 97 | } 98 | } 99 | splits { 100 | abi { 101 | reset() 102 | enable enableSeparateBuildPerCPUArchitecture 103 | universalApk false // If true, also generate a universal APK 104 | include "armeabi-v7a", "x86" 105 | } 106 | } 107 | buildTypes { 108 | release { 109 | minifyEnabled enableProguardInReleaseBuilds 110 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 111 | } 112 | } 113 | // applicationVariants are e.g. debug, release 114 | applicationVariants.all { variant -> 115 | variant.outputs.each { output -> 116 | // For each separate APK per architecture, set a unique version code as described here: 117 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 118 | def versionCodes = ["armeabi-v7a":1, "x86":2] 119 | def abi = output.getFilter(OutputFile.ABI) 120 | if (abi != null) { // null for the universal-debug, universal-release variants 121 | output.versionCodeOverride = 122 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 123 | } 124 | } 125 | } 126 | } 127 | 128 | dependencies { 129 | compile fileTree(dir: "libs", include: ["*.jar"]) 130 | compile "com.android.support:appcompat-v7:23.0.1" 131 | compile "com.facebook.react:react-native:+" // From node_modules 132 | } 133 | 134 | // Run this once to be able to run the application with BUCK 135 | // puts all compile dependencies into folder libs for BUCK to use 136 | task copyDownloadableDepsToLibs(type: Copy) { 137 | from configurations.compile 138 | into 'libs' 139 | } 140 | -------------------------------------------------------------------------------- /Example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # okhttp 54 | 55 | -keepattributes Signature 56 | -keepattributes *Annotation* 57 | -keep class okhttp3.** { *; } 58 | -keep interface okhttp3.** { *; } 59 | -dontwarn okhttp3.** 60 | 61 | # okio 62 | 63 | -keep class sun.misc.Unsafe { *; } 64 | -dontwarn java.nio.file.* 65 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 66 | -dontwarn okio.** 67 | -------------------------------------------------------------------------------- /Example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "Example"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Example/android/app/src/main/java/com/example/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Application; 4 | import android.util.Log; 5 | 6 | import com.facebook.react.ReactApplication; 7 | import com.facebook.react.ReactInstanceManager; 8 | import com.facebook.react.ReactNativeHost; 9 | import com.facebook.react.ReactPackage; 10 | import com.facebook.react.shell.MainReactPackage; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | public class MainApplication extends Application implements ReactApplication { 16 | 17 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 18 | @Override 19 | protected boolean getUseDeveloperSupport() { 20 | return BuildConfig.DEBUG; 21 | } 22 | 23 | @Override 24 | protected List getPackages() { 25 | return Arrays.asList( 26 | new MainReactPackage() 27 | ); 28 | } 29 | }; 30 | 31 | @Override 32 | public ReactNativeHost getReactNativeHost() { 33 | return mReactNativeHost; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Example 3 | 4 | -------------------------------------------------------------------------------- /Example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.3.1' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | maven { 20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 21 | url "$rootDir/../node_modules/react-native/android" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/Example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 6 | -------------------------------------------------------------------------------- /Example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Example/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = 'debug', 3 | store = 'debug.keystore', 4 | properties = 'debug.keystore.properties', 5 | visibility = [ 6 | 'PUBLIC', 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /Example/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /Example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Example' 2 | 3 | include ':app' 4 | -------------------------------------------------------------------------------- /Example/index.android.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | AppRegistry, 10 | StyleSheet, 11 | Text, 12 | View 13 | } from 'react-native'; 14 | 15 | class Example extends Component { 16 | render() { 17 | return ( 18 | 19 | 20 | Welcome to React Native! 21 | 22 | 23 | To get started, edit index.android.js 24 | 25 | 26 | Shake or press menu button for dev menu 27 | 28 | 29 | ); 30 | } 31 | } 32 | 33 | const styles = StyleSheet.create({ 34 | container: { 35 | flex: 1, 36 | justifyContent: 'center', 37 | alignItems: 'center', 38 | backgroundColor: '#F5FCFF', 39 | }, 40 | welcome: { 41 | fontSize: 20, 42 | textAlign: 'center', 43 | margin: 10, 44 | }, 45 | instructions: { 46 | textAlign: 'center', 47 | color: '#333333', 48 | marginBottom: 5, 49 | }, 50 | }); 51 | 52 | AppRegistry.registerComponent('Example', () => Example); 53 | -------------------------------------------------------------------------------- /Example/index.ios.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, {Component} from 'react'; 8 | import { 9 | AppRegistry, 10 | StyleSheet, 11 | Text, 12 | View, 13 | TouchableHighlight 14 | } from 'react-native'; 15 | 16 | import { 17 | startRecognition 18 | } from 'react-native-baidu-voice-recognition'; 19 | 20 | const styles = StyleSheet.create({ 21 | container: { 22 | flex: 1 23 | }, 24 | textContainer: { 25 | flex: 1, 26 | padding: 10, 27 | marginTop: 20 28 | }, 29 | text: { 30 | fontSize: 12, 31 | lineHeight: 18 32 | }, 33 | instructions: { 34 | textAlign: 'center', 35 | color: '#333333', 36 | marginBottom: 5 37 | } 38 | }); 39 | 40 | const API_KEY = 'g8ylHecLtt4WyTuPFG7Fssu0'; 41 | const SECRET_KEY = '391b8964cb174efc85eac80b5fcf6be5'; 42 | 43 | class Example extends Component { 44 | 45 | constructor(props) { 46 | super(props); 47 | this.state = { 48 | recognizing: false, 49 | content: 'Welcome To ReactNative!', 50 | buffer: '' 51 | }; 52 | } 53 | 54 | async startRecognition() { 55 | 56 | const me = this; 57 | 58 | me.setState({ 59 | recording: true 60 | }); 61 | 62 | if (me.recognition) { 63 | await me.recognition.cancel(); 64 | me.recognition = null; 65 | } 66 | 67 | me.recognition = await startRecognition({ 68 | apiKey: API_KEY, 69 | secretKey: SECRET_KEY, 70 | onStart() { 71 | console.log('start'); 72 | me.setState({ 73 | recognizing: true 74 | }); 75 | }, 76 | onSpeechStart() { 77 | console.log('speech-start'); 78 | }, 79 | onFlushData(data) { 80 | me.setState({ 81 | buffer: data.results[0] 82 | }); 83 | }, 84 | onCancel() { 85 | me.recognition = null; 86 | me.setState({ 87 | recognizing: false, 88 | buffer: '' 89 | }); 90 | }, 91 | onError(error) { 92 | console.log(error); 93 | me.recognition = null; 94 | me.setState({ 95 | recording: false, 96 | recognizing: false, 97 | buffer: '' 98 | }); 99 | }, 100 | onFinish(data) { 101 | console.log('finish'); 102 | me.recognition = null; 103 | me.setState({ 104 | recording: false, 105 | recognizing: false, 106 | content: `${me.state.content}\n${data.results[0]}`, 107 | buffer: '' 108 | }); 109 | } 110 | }); 111 | 112 | } 113 | 114 | async finishRecognition() { 115 | 116 | if (!this.recognition) { 117 | return; 118 | } 119 | 120 | if (Date.now() - this.recognition.timestamp > 1000) { 121 | if (this.state.recording) { 122 | this.setState({ 123 | recording: false 124 | }); 125 | } 126 | await this.recognition.finish(); 127 | } 128 | else { 129 | await this.recognition.cancel(); 130 | } 131 | 132 | } 133 | 134 | render() { 135 | 136 | const { 137 | content, 138 | buffer, 139 | recording, 140 | recognizing 141 | } = this.state; 142 | 143 | return ( 144 | 145 | 146 | 147 | {`${content}${buffer ? '\n' + buffer : ''}`} 148 | 149 | 150 | { 159 | this.startRecognition(); 160 | }} 161 | onPressOut={() => { 162 | this.finishRecognition(); 163 | }} 164 | underlayColor="#008075"> 165 | 166 | 167 | {recording 168 | ? '录音中...' 169 | : recognizing ? '解析中...' : 'Start Voice Recognition'} 170 | 171 | 172 | 173 | 174 | ); 175 | } 176 | } 177 | 178 | 179 | 180 | AppRegistry.registerComponent('Example', () => Example); 181 | -------------------------------------------------------------------------------- /Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /Example/ios/Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Example/ios/Example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "AppDelegate.h" 11 | 12 | #import "RCTBundleURLProvider.h" 13 | #import "RCTRootView.h" 14 | 15 | @implementation AppDelegate 16 | 17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 18 | { 19 | NSURL *jsCodeLocation; 20 | 21 | [[RCTBundleURLProvider sharedSettings] setDefaults]; 22 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; 23 | 24 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 25 | moduleName:@"Example" 26 | initialProperties:nil 27 | launchOptions:launchOptions]; 28 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 29 | 30 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 31 | UIViewController *rootViewController = [UIViewController new]; 32 | rootViewController.view = rootView; 33 | self.window.rootViewController = rootViewController; 34 | [self.window makeKeyAndVisible]; 35 | return YES; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Example/ios/Example/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Example/ios/Example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/ios/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | NSExceptionDomains 30 | 31 | localhost 32 | 33 | NSTemporaryExceptionAllowsInsecureHTTPLoads 34 | 35 | 36 | 37 | 38 | NSLocationWhenInUseUsageDescription 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UIViewControllerBasedStatusBarAppearance 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Example/ios/Example/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | #import "AppDelegate.h" 13 | 14 | int main(int argc, char * argv[]) { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Example/ios/ExampleTests/ExampleTests.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | #import 12 | 13 | #import "RCTLog.h" 14 | #import "RCTRootView.h" 15 | 16 | #define TIMEOUT_SECONDS 600 17 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" 18 | 19 | @interface ExampleTests : XCTestCase 20 | 21 | @end 22 | 23 | @implementation ExampleTests 24 | 25 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 26 | { 27 | if (test(view)) { 28 | return YES; 29 | } 30 | for (UIView *subview in [view subviews]) { 31 | if ([self findSubviewInView:subview matching:test]) { 32 | return YES; 33 | } 34 | } 35 | return NO; 36 | } 37 | 38 | - (void)testRendersWelcomeScreen 39 | { 40 | UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; 41 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 42 | BOOL foundElement = NO; 43 | 44 | __block NSString *redboxError = nil; 45 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 46 | if (level >= RCTLogLevelError) { 47 | redboxError = message; 48 | } 49 | }); 50 | 51 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 52 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 53 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 54 | 55 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 56 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 57 | return YES; 58 | } 59 | return NO; 60 | }]; 61 | } 62 | 63 | RCTSetLogFunction(RCTDefaultLogFunction); 64 | 65 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 66 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 67 | } 68 | 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /Example/ios/ExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start" 7 | }, 8 | "dependencies": { 9 | "react": "15.2.0", 10 | "react-native": "0.29.0", 11 | "react-native-baidu-voice-recognition": "file:../" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # ReactNative 百度语音识别 SDK 2 | 3 | iOS supported 4 | 5 | Android coming soon 6 | 7 | ## setup 8 | 9 | 1. 安装依赖 10 | 11 | ```sh 12 | npm install -S react-native-baidu-voice-recognition 13 | ``` 14 | 15 | 2. 使用 rnpm 搞定 xcode 16 | 17 | ```sh 18 | rnpm link react-native-baidu-voice-recognition 19 | ``` 20 | 21 | 22 | > 在线识别需要网络连接,所以需要在 Info.plist 中打开 SSL 请求限制 23 | > 以 source code 方式打开 Info.plist 文件后加入下边的代码: 24 | > 25 | > ![image](https://cloud.githubusercontent.com/assets/811195/16713960/7c4912fc-46e8-11e6-950f-d043cf92c25c.png) 26 | 27 | ## Usage 28 | 29 | ```js 30 | 31 | import {startRecognition} from 'react-native-baidu-voice-recognition'; 32 | 33 | const recognition = startRecognition({ 34 | 35 | // 这两个请到 http://yuyin.baidu.com 上来申请 app 后查看哈 36 | apiKey: 'YOUR_BAIDU_YUYIN_APP_API_KEY', 37 | secretKey: 'YOUR_BAIDU_YUYIN_APP_SECERT_KEY', 38 | 39 | // 开始解析 40 | onStart() { 41 | 42 | }, 43 | 44 | // 检测到用户开始说话 45 | onSpeechStart() { 46 | 47 | }, 48 | 49 | // 用户结束说话 50 | onSpeechEnd() { 51 | 52 | }, 53 | 54 | // 解析出部分数据 55 | // 此回调可能会被调用若干次,每次都会带有前边解析出的数据 56 | // 例如三次 onFlushData 回调可能分别得到数据:啊,啊啊,啊啊啊 57 | onFlushData(data) { 58 | 59 | // 数据结构是这样的 60 | { 61 | results: ['啊', '哈'] 62 | } 63 | 64 | }, 65 | 66 | // 完成解析 67 | onFinish(data) { 68 | // 数据结构是这样的 69 | { 70 | results: ['啊', '哈'] 71 | } 72 | }, 73 | 74 | // 用户说话音量大小变化 75 | onMeterLevel() { 76 | 77 | }, 78 | 79 | // 主动取消解析 80 | onCancel() { 81 | 82 | }, 83 | 84 | // 解析发生错误 85 | onError() { 86 | 87 | } 88 | 89 | }); 90 | 91 | setTimeout(function () { 92 | 93 | if (Date.now() - recognition.timestamp > 1000) { 94 | 95 | // 可以主动结束录音 96 | recognition.finish(); 97 | 98 | } 99 | else { 100 | // 或者也可以主动 101 | recognition.cancel(); 102 | } 103 | 104 | }, Math.round(Math.random() * 2000)); 105 | 106 | ``` 107 | 108 | ## TODO 109 | 110 | [ ] Android 支持 111 | [ ] 唤醒支持 112 | [ ] 离线版本支持 113 | -------------------------------------------------------------------------------- /doc/百度语音开放平台-iOS-SDK文档.md: -------------------------------------------------------------------------------- 1 | #百度语音开放平台-iOS SDK文档 2 | 3 | ##1. 概述 4 | 本文档是百度语音开放平台iOS SDK的用户指南,描述了`语音识别`、`语音唤醒`、`语音合成`等相关接口的使用说明。 5 | ###资源占用描述 6 | 7 | 静态库占用: 8 | 9 | SDK类型 | 静态库大小 | 二进制增量 | __TEXT增量| 10 | -------|-------|-------|-------| 11 | 识别+唤醒|62.5M|1.9M|1.0M~1.2M| 12 | 13 | 资源占用: 14 | 15 | 资源类型 | 资源大小 | 16 | -------|-------| 17 | 唤醒语言模型|2.3M| 18 | 离线命令词语言模型|2.3M| 19 | 离线输入法语言模型|56.8M| 20 | 21 | ``` 22 | 由于 BITCODE 开启会导致二进制文件体积增大,这部分会在 APPStore 发布时进行进一步编译优化,并不会引起最终文件的体积变化,故此处计算的是关闭 BITCODE 下的二进制增量。 23 | ``` 24 | 25 | ##2. 集成(略) 26 | ##3. 语音识别接口 27 | 语音识别包含数据上传接口和离在线识别接口,接口概述如下: 28 | 29 | 1. 创建相关接口对象 (createEventManagerWithName:) 30 | 2. 设置代理对象 (setDelegate:) 31 | 3. 配置参数 (setParameter:forKey:) 32 | 4. 发送预定义指令 (sendCommand:) 33 | 5. 参数列表见相关parameters头文件,预定义值见相关defines头文件 34 | 35 | ###3.1 数据上传接口 36 | ####3.1.1 代码示例 37 | ```objc 38 | // 创建数据上传对象 39 | self.uploaderEventManager = [BDSEventManager createEventManagerWithName:BDS_UPLOADER_NAME]; 40 | // 设置数据上传代理 41 | [self.uploaderEventManager setDelegate:self]; 42 | // 参数配置:词条名 43 | [self.uploaderEventManager setParameter:@"songs" forKey:BDS_UPLOADER_SLOT_NAME]; 44 | // 参数配置:词条 45 | [self.uploaderEventManager setParameter:@[@"百度", @"语音"] forKey:BDS_UPLOADER_SLOT_WORDS]; 46 | // 启动上传 47 | [self.uploaderEventManager sendCommand:BDS_UP_CMD_START]; 48 | ``` 49 | ####3.1.2 词条说明 50 | 51 | 词条名 | 功能描述 52 | ----- | ------- 53 | songs | 歌曲词条 54 | contacts | 通讯录词条 55 | 56 | ####3.1.3 上传功能代理: 57 | ```objc 58 | @protocol BDSClientUploaderDelegate 59 | - (void)UploadCompleteWithError:(NSError *)error; 60 | @end 61 | ``` 62 | ###3.2 识别接口 63 | ####3.2.1 在线识别代码示例 64 | ```objc 65 | // 创建语音识别对象 66 | self.asrEventManager = [BDSEventManager createEventManagerWithName:BDS_ASR_NAME]; 67 | // 设置语音识别代理 68 | [self.asrEventManager setDelegate:self]; 69 | // 参数配置:在线身份验证 70 | [self.asrEventManager setParameter:@[API_KEY, SECRET_KEY] forKey:BDS_ASR_API_SECRET_KEYS]; 71 | // 参数配置:垂类设置 72 | [self.asrEventManager setParameter:@[@(EVoiceRecognitionPropertySearch)] forKey:BDS_ASR_PROPERTY_LIST]; 73 | // 发送指令:启动识别 74 | [self.asrEventManager sendCommand:BDS_ASR_CMD_START]; 75 | ``` 76 | ####3.2.2 离线识别代码示例 77 | ```objc 78 | // 创建语音识别对象 79 | self.asrEventManager = [BDSEventManager createEventManagerWithName:BDS_ASR_NAME]; 80 | // 设置语音识别代理 81 | [self.asrEventManager setDelegate:self]; 82 | // 参数设置:识别策略 83 | [self.asrEventManager setParameter:@(EVR_STRATEGY_OFFLINE) forKey:BDS_ASR_STRATEGY]; 84 | // 参数设置:离线识别引擎类型 85 | [self.asrEventManager setParameter:@(EVR_OFFLINE_ENGINE_GRAMMER) forKey:BDS_ASR_OFFLINE_ENGINE_TYPE]; 86 | // 参数配置:离线授权APPID 87 | [self.asrEventManager setParameter:@"Your APPID" forKey:BDS_ASR_OFFLINE_APP_CODE]; 88 | // 参数配置:命令词引擎语法文件路径 89 | [self.asrEventManager setParameter:@"命令词引擎语法文件路径" forKey:BDS_ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH]; 90 | // 参数配置:命令词引擎语言模型文件路径 91 | [self.asrEventManager setParameter:@"命令词引擎语言模型文件路径" forKey:BDS_ASR_OFFLINE_ENGINE_DAT_FILE_PATH]; 92 | // 发送指令:加载离线引擎 93 | [self.asrEventManager sendCommand:BDS_ASR_CMD_LOAD_ENGINE]; 94 | // 发送指令:启动识别 95 | [self.asrEventManager sendCommand:BDS_ASR_CMD_START]; 96 | ``` 97 | ####3.2.3 识别功能代理: 98 | ```objc 99 | @protocol BDSClientASRDelegate 100 | - (void)VoiceRecognitionClientWorkStatus:(int)workStatus obj:(id)aObj; 101 | @end 102 | ``` 103 | ##4. 语音唤醒接口 104 | 语音唤醒为离线功能,需配置离线授权信息(临时授权文件或开放平台申请的APPID),加载唤醒所需语言模型文件,接口与语音识别接口相同。 105 | ###4.1 代码示例 106 | ```objc 107 | // 创建语音识别对象 108 | self.wakeupEventManager = [BDSEventManager createEventManagerWithName:BDS_WAKEUP_NAME]; 109 | // 设置语音唤醒代理 110 | [self.wakeupEventManager setDelegate:self]; 111 | // 参数配置:离线授权APPID 112 | [self.wakeupEventManager setParameter:@"Your APPID" forKey:BDS_WAKEUP_APP_CODE]; 113 | // 参数配置:唤醒语言模型文件路径 114 | [self.wakeupEventManager setParameter:@"唤醒语言模型文件路径" forKey:BDS_WAKEUP_DAT_FILE_PATH]; 115 | // 发送指令:加载语音唤醒引擎 116 | [self.wakeupEventManager sendCommand:BDS_WP_CMD_LOAD_ENGINE]; 117 | // 发送指令:启动唤醒 118 | [self.wakeupEventManager sendCommand:BDS_WP_CMD_START]; 119 | ``` 120 | ###4.2 唤醒功能回调接口: 121 | ```objc 122 | @protocol BDSClientWakeupDelegate 123 | - (void)WakeupClientWorkStatus:(int)workStatus obj:(id)aObj; 124 | @end 125 | ``` 126 | ###4.3 唤醒辅助识别说明 127 | 如需要唤醒后立刻进行识别,为保证不丢音,启动语音识别前请添加如下配置,获取录音缓存: 128 | 129 | ```objc 130 | [self.asrEventManager setParameter:@(YES) forKey:BDS_ASR_NEED_CACHE_AUDIO]; 131 | ``` 132 | ##5. 语音合成接口(略) 133 | ##6. 常见问题 134 | ##7. 附录 135 | ###7.1 音频数据源配置 136 | 目前SDK支持三种音频数据源。说明如下: 137 | 138 | 音频数据源 | 优先级 | 说明 139 | ------- | ------- | ------- 140 | 文件输入 | 高 | 8K或16K采样率、单声道PCM格式音频文件 141 | 输入流 | 中 | 用以支持外接音源,如车载录音机 142 | 本地录音机 | 低 | 手机设备内置录音功能 143 | > 默认使用本地录音机,如设置过文件或输入流相关参数,将其置空即可恢复为默认设置; 144 | > 录音模块运行时,切换数据源不生效; 145 | > 多模块共享录音模块,重复设置会产生覆盖; 146 | 147 | ###7.2 语音识别策略 148 | 目前SDK支持五种识别策略。说明如下: 149 | 150 | 识别策略 | 说明 151 | ------- | ------- 152 | 在线识别 | 识别请求发至语音服务器进行解析 153 | 离线识别 | 本地完成语音识别解析工作 154 | 在线优先 | 在线识别失败后,自动切换至离线识别 155 | 离线优先 | 离线识别失败后,自动切换至在线识别 156 | 并行模式 | 离在线识别同时进行,取第一个返回的识别结果 157 | 158 | ###7.3 引擎验证方法 159 | 在线识别、离线识别与唤醒都需要进行相关验证后方可使用: 160 | 161 | 引擎类型 | 验证方法 162 | --------- | --------- 163 | 在线识别 | 开放平台使用API/SECRET KEY进行验证 164 | 离线识别 | 测试可以使用临时授权文件,正式版本请移除临时授权文件,
使用APPID进行验证 165 | 唤醒引擎 | 与离线识别验证方法一致 166 | 167 | ###7.4 离线识别引擎类型 168 | 离线识别引擎有两种类型,对应不同工作模式: 169 | 170 | 引擎类型 | 描述 171 | ------- | ------- 172 | 语法模式 | 该模式需要配置资源文件和语法文件,
离线引擎将根据传入的语法文件进行相关的匹配识别 173 | 输入法模式 | 该模式需要配置资源文件,进行普通模式的识别,
即对输入的语音进行识别,类似与在线识别 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /doc/百度语音开放平台-iOS-SDK文档.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/doc/百度语音开放平台-iOS-SDK文档.pdf -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file BaiduVoiceRecognition 3 | * @author leon 4 | */ 5 | 6 | import { 7 | NativeModules, 8 | NativeAppEventEmitter 9 | } from 'react-native'; 10 | 11 | const Recognition = NativeModules.ReactNativeBaiduVoiceRecognition; 12 | 13 | const { 14 | VoiceRecognitionEventName, 15 | EVoiceRecognitionClientWorkStatusStartWorkIng, 16 | EVoiceRecognitionClientWorkStatusStart, 17 | EVoiceRecognitionClientWorkStatusEnd, 18 | // EVoiceRecognitionClientWorkStatusNewRecordData, 19 | EVoiceRecognitionClientWorkStatusFlushData, 20 | EVoiceRecognitionClientWorkStatusFinish, 21 | EVoiceRecognitionClientWorkStatusMeterLevel, 22 | EVoiceRecognitionClientWorkStatusCancel, 23 | EVoiceRecognitionClientWorkStatusError, 24 | EVoiceRecognitionClientWorkStatusLoaded, 25 | EVoiceRecognitionClientWorkStatusUnLoaded 26 | } = Recognition; 27 | 28 | export const RecognitionClientWorkStatus = { 29 | startworking: EVoiceRecognitionClientWorkStatusStartWorkIng, 30 | start: EVoiceRecognitionClientWorkStatusStart, 31 | end: EVoiceRecognitionClientWorkStatusEnd, 32 | // newrecorddata: EVoiceRecognitionClientWorkStatusNewRecordData, 33 | flushdata: EVoiceRecognitionClientWorkStatusFlushData, 34 | finish: EVoiceRecognitionClientWorkStatusFinish, 35 | meterlevel: EVoiceRecognitionClientWorkStatusMeterLevel, 36 | cancel: EVoiceRecognitionClientWorkStatusCancel, 37 | error: EVoiceRecognitionClientWorkStatusError, 38 | loaded: EVoiceRecognitionClientWorkStatusLoaded, 39 | unloaded: EVoiceRecognitionClientWorkStatusUnLoaded 40 | }; 41 | 42 | const RECOGNITION_CLIENT_WORK_STATUS_2_HANDLER = { 43 | [EVoiceRecognitionClientWorkStatusStartWorkIng]: 'onStart', 44 | [EVoiceRecognitionClientWorkStatusStart]: 'onSpeechStart', 45 | [EVoiceRecognitionClientWorkStatusEnd]: 'onSpeechEnd', 46 | // [EVoiceRecognitionClientWorkStatusNewRecordData]: 'onNewRecordData', 47 | [EVoiceRecognitionClientWorkStatusFlushData]: 'onFlushData', 48 | [EVoiceRecognitionClientWorkStatusFinish]: 'onFinish', 49 | [EVoiceRecognitionClientWorkStatusMeterLevel]: 'onMeterLevel', 50 | [EVoiceRecognitionClientWorkStatusCancel]: 'onCancel', 51 | [EVoiceRecognitionClientWorkStatusError]: 'onError', 52 | [EVoiceRecognitionClientWorkStatusLoaded]: 'onLoaded', 53 | [EVoiceRecognitionClientWorkStatusUnLoaded]: 'onUnloaded' 54 | }; 55 | 56 | const RECOGNITION_CLIENT_WORK_STATUS_2_NAME = { 57 | [EVoiceRecognitionClientWorkStatusStartWorkIng]: 'startworking', 58 | [EVoiceRecognitionClientWorkStatusStart]: 'start', 59 | [EVoiceRecognitionClientWorkStatusEnd]: 'end', 60 | // [EVoiceRecognitionClientWorkStatusNewRecordData]: 'newrecorddata', 61 | [EVoiceRecognitionClientWorkStatusFlushData]: 'flushdata', 62 | [EVoiceRecognitionClientWorkStatusFinish]: 'finish', 63 | [EVoiceRecognitionClientWorkStatusMeterLevel]: 'meterlevel', 64 | [EVoiceRecognitionClientWorkStatusCancel]: 'cancel', 65 | [EVoiceRecognitionClientWorkStatusError]: 'error', 66 | [EVoiceRecognitionClientWorkStatusLoaded]: 'loaded', 67 | [EVoiceRecognitionClientWorkStatusUnLoaded]: 'unloaded' 68 | }; 69 | 70 | export async function startRecognition(options = {}) { 71 | 72 | const { 73 | apiKey, 74 | secretKey, 75 | onWorkStatusChange 76 | } = options; 77 | 78 | const subscription = NativeAppEventEmitter.addListener( 79 | VoiceRecognitionEventName, 80 | recognitionHandler 81 | ); 82 | 83 | function recognitionHandler(event) { 84 | 85 | let { 86 | status, 87 | data 88 | } = event; 89 | 90 | if (data 91 | && ( 92 | status === EVoiceRecognitionClientWorkStatusFlushData 93 | || status === EVoiceRecognitionClientWorkStatusFinish 94 | ) 95 | ) { 96 | 97 | data = JSON.parse(data); 98 | data = { 99 | results: data.results_recognition, 100 | originResults: data.origin_result 101 | }; 102 | 103 | } 104 | 105 | if (typeof onWorkStatusChange === 'function') { 106 | onWorkStatusChange({ 107 | data, 108 | status, 109 | type: RECOGNITION_CLIENT_WORK_STATUS_2_NAME[status] 110 | }); 111 | } 112 | 113 | const eventHandlerName = RECOGNITION_CLIENT_WORK_STATUS_2_HANDLER[status]; 114 | const eventHandler = options[eventHandlerName]; 115 | 116 | if (typeof eventHandler === 'function') { 117 | eventHandler(data); 118 | } 119 | 120 | if (status === EVoiceRecognitionClientWorkStatusFinish 121 | || status === EVoiceRecognitionClientWorkStatusError 122 | ) { 123 | subscription.remove(); 124 | } 125 | 126 | } 127 | 128 | async function cancel() { 129 | NativeAppEventEmitter.removeListener(recognitionHandler); 130 | await Recognition.cancelRecognition(); 131 | } 132 | 133 | async function finish() { 134 | await Recognition.finishRecognition(); 135 | } 136 | 137 | await Recognition.startRecognition(apiKey, secretKey); 138 | 139 | return { 140 | cancel, 141 | finish, 142 | timestamp: Date.now() 143 | }; 144 | 145 | } 146 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/.gitIgnore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/ios/BaiduVoiceSDK/BDSClientHeaders/ASR/.gitIgnore -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/BDSASRDefines.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSASRDefines.h 3 | // BDSpeechClient 4 | // 5 | // Created by baidu on 16/6/6. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #ifndef BDSASRDefines_h 10 | #define BDSASRDefines_h 11 | 12 | #import 13 | 14 | #pragma mark - ASR Delegate 15 | @protocol BDSClientASRDelegate 16 | - (void)VoiceRecognitionClientWorkStatus:(int)workStatus obj:(id)aObj; // TBDVoiceRecognitionClientWorkStatus 17 | @end 18 | 19 | #pragma mark - ASR Command 20 | extern NSString* BDS_ASR_CMD_START; 21 | extern NSString* BDS_ASR_CMD_STOP; 22 | extern NSString* BDS_ASR_CMD_CANCEL; 23 | extern NSString* BDS_ASR_CMD_LOAD_ENGINE; 24 | extern NSString* BDS_ASR_CMD_UNLOAD_ENGINE; 25 | 26 | #pragma mark - 设定采样率 27 | typedef enum TBDVoiceRecognitionRecordSampleRateFlags 28 | { 29 | EVoiceRecognitionRecordSampleRateAuto = 0, 30 | EVoiceRecognitionRecordSampleRate8K, 31 | EVoiceRecognitionRecordSampleRate16K, 32 | } TBDVoiceRecognitionRecordSampleRateFlags; 33 | 34 | #pragma mark - 设置识别语言 35 | typedef enum TBDVoiceRecognitionLanguage 36 | { 37 | EVoiceRecognitionLanguageChinese = 0, 38 | EVoiceRecognitionLanguageCantonese, 39 | EVoiceRecognitionLanguageEnglish, 40 | EVoiceRecognitionLanguageSichuanDialect, 41 | } TBDVoiceRecognitionLanguage; 42 | 43 | #pragma mark - 提示音类型 44 | typedef enum TBDVoiceRecognitionPlayTones 45 | { 46 | EVRPlayToneTypeStart = (1 << 0), // 开始识别提示音, record_start.caf (会影响端点检测准确率,建议不要与端点检测同时开启) 47 | EVRPlayToneTypeEnd = (1 << 1), // 结束识别提示音, record_end.caf 48 | EVRPlayToneTypeSuccess = (1 << 2), // 识别成功提示音, record_success.caf 49 | EVRPlayToneTypeFail = (1 << 3), // 识别失败提示音, record_fail.caf 50 | EVRPlayToneTypeCancel = (1 << 4), // 取消识别提示音, record_cancel.caf 51 | EVRPlayToneNone = 0, // 关闭提示音 52 | EVRPlayToneAll = (EVRPlayToneTypeEnd | EVRPlayToneTypeSuccess | EVRPlayToneTypeFail | EVRPlayToneTypeCancel) // 打开所有提示音 53 | } TBDVoiceRecognitionPlayTones; 54 | 55 | #pragma mark - 语音识别策略 56 | typedef enum TBDVoiceRecognitionStrategy 57 | { 58 | EVR_STRATEGY_ONLINE = 0, // 在线识别 59 | EVR_STRATEGY_OFFLINE, // 离线识别 60 | EVR_STRATEGY_ONLINE_PRI, // 在线优先 61 | EVR_STRATEGY_OFFLINE_PRI, // 离线优先 62 | EVR_STRATEGY_BOTH, // 并行模式 63 | } TBDVoiceRecognitionStrategy; 64 | 65 | #pragma mark - 语音识别离线引擎类型 66 | typedef enum TBDVoiceRecognitionOfflineEngineType 67 | { 68 | EVR_OFFLINE_ENGINE_INPUT = 0, // 离线引擎输入法模式 69 | EVR_OFFLINE_ENGINE_NAVI, // 离线引擎导航模式 70 | EVR_OFFLINE_ENGINE_GRAMMER, // 离线引擎语法模式 71 | } TBDVoiceRecognitionOfflineEngineType; 72 | 73 | #pragma mark - 语音识别类型 74 | typedef enum TBDVoiceRecognitionProperty 75 | { 76 | EVoiceRecognitionPropertyMusic = 10001, // 音乐 77 | EVoiceRecognitionPropertyVideo = 10002, // 视频 78 | EVoiceRecognitionPropertyApp = 10003, // 应用 79 | EVoiceRecognitionPropertyWeb = 10004, // web 80 | EVoiceRecognitionPropertySearch = 10005, // 热词 81 | EVoiceRecognitionPropertyEShopping = 10006, // 电商&购物 82 | EVoiceRecognitionPropertyHealth = 10007, // 健康&母婴 83 | EVoiceRecognitionPropertyCall = 10008, // 打电话 84 | EVoiceRecognitionPropertySong = 10009, // 录歌识别 85 | EVoiceRecognitionPropertyShake = 10010, // 摇一摇拾台 86 | EVoiceRecognitionPropertyMedicalCare = 10052, // 医疗 87 | EVoiceRecognitionPropertyCar = 10053, // 汽车 88 | EVoiceRecognitionPropertyCatering = 10054, // 娱乐餐饮 89 | EVoiceRecognitionPropertyFinanceAndEconomics = 10055, // 财经 90 | EVoiceRecognitionPropertyGame = 10056, // 游戏 91 | EVoiceRecognitionPropertyCookbook = 10057, // 菜谱 92 | EVoiceRecognitionPropertyAssistant = 10058, // 助手 93 | EVoiceRecognitionPropertyRecharge = 10059, // 话费充值 94 | EVoiceRecognitionPropertyMap = 10060, // 地图 95 | EVoiceRecognitionPropertyInput = 20000, // 输入 96 | } TBDVoiceRecognitionProperty; 97 | 98 | #pragma mark - 语音识别状态 99 | typedef enum TBDVoiceRecognitionClientWorkStatus 100 | { 101 | EVoiceRecognitionClientWorkStatusStartWorkIng, // 识别工作开始,开始采集及处理数据 102 | EVoiceRecognitionClientWorkStatusStart, // 检测到用户开始说话 103 | EVoiceRecognitionClientWorkStatusEnd, // 本地声音采集结束结束,等待识别结果返回并结束录音 104 | EVoiceRecognitionClientWorkStatusNewRecordData, // 录音数据回调 105 | EVoiceRecognitionClientWorkStatusFlushData, // 连续上屏 106 | EVoiceRecognitionClientWorkStatusFinish, // 语音识别功能完成,服务器返回正确结果 107 | EVoiceRecognitionClientWorkStatusMeterLevel, // 当前音量回调 108 | EVoiceRecognitionClientWorkStatusCancel, // 用户取消 109 | EVoiceRecognitionClientWorkStatusError, // 发生错误,详情见VoiceRecognitionClientErrorInfo接口通知 110 | /* 离线引擎状态 */ 111 | EVoiceRecognitionClientWorkStatusLoaded, // 离线引擎加载完成 112 | EVoiceRecognitionClientWorkStatusUnLoaded, // 离线引擎卸载完成 113 | } TBDVoiceRecognitionClientWorkStatus; 114 | 115 | #pragma mark - 语音识别错误通知状态分类 116 | typedef enum TVoiceRecognitionClientErrorDomain 117 | { 118 | EVRClientErrorDomainRecord = 10, // 录音设备出错 119 | EVRClientErrorDomainVAD = 20, // 语音数据处理过程出错 120 | EVRClientErrorDomainOnline = 30, // 在线识别引擎出错 121 | EVRClientErrorDomainLocalNetwork = 31, // 本地网络联接出错 122 | EVRClientErrorDomainHTTP = 32, // HTTP协议错误 123 | EVRClientErrorDomainServer = 33, // 服务器返回错误 124 | EVRClientErrorDomainOffline = 34, // 离线引擎返回错误 125 | EVRClientErrorDomainCommom = 40, // 其他错误 126 | } TVoiceRecognitionClientErrorDomain; 127 | 128 | #pragma mark - 语音识别错误通知状态 129 | typedef enum TVoiceRecognitionClientErrorCode 130 | { 131 | EVRClientErrorCodeRecoderException = (EVRClientErrorDomainRecord << 16) | (0x0000FFFF & 1), // 录音设备异常 132 | EVRClientErrorCodeRecoderNoPermission = (EVRClientErrorDomainRecord << 16) | (0x0000FFFF & 2), // 无录音权限 133 | EVRClientErrorCodeRecoderUnAvailable = (EVRClientErrorDomainRecord << 16) | (0x0000FFFF & 3), // 录音设备不可用 134 | EVRClientErrorCodeInterruption = (EVRClientErrorDomainRecord << 16) | (0x0000FFFF & 4), // 录音中断 135 | 136 | EVRClientErrorCodeVADException = (EVRClientErrorDomainVAD << 16) | (0x0000FFFF & 1), // 前端库异常 137 | EVRClientErrorCodeNoSpeech = (EVRClientErrorDomainVAD << 16) | (0x0000FFFF & 2), // 用户未说话 138 | EVRClientErrorCodeShort = (EVRClientErrorDomainVAD << 16) | (0x0000FFFF & 3), // 用户说话声音太短 139 | 140 | EVRClientErrorCodeDecoderExceptioin = (EVRClientErrorDomainOnline << 16) | (0x0000FFFF & 1), // 在线识别引擎异常 141 | EVRClientErrorCodeDecoderNetworkUnavailable = (EVRClientErrorDomainOnline << 16) | (0x0000FFFF & 2), // 网络不可用 142 | EVRClientErrorCodeDecoderTokenFailed = (EVRClientErrorDomainOnline << 16) | (0x0000FFFF & 3), // 获取token失败 143 | EVRClientErrorCodeDecoderResolveUrlFailed = (EVRClientErrorDomainOnline << 16) | (0x0000FFFF & 4), // 解析url失败 144 | EVRClientErrorCodeLocalTimeout = (EVRClientErrorDomainLocalNetwork << 16) | (0x0000FFFF & 1), // 请求超时 145 | 146 | EVRClientErrorCodeServerParamError = (EVRClientErrorDomainServer << 16) | (0x0000FFFF & -3001), // 协议参数错误 147 | EVRClientErrorCodeServerRecognError = (EVRClientErrorDomainServer << 16) | (0x0000FFFF & -3002), // 识别过程出错 148 | EVRClientErrorCodeServerNoFindResult = (EVRClientErrorDomainServer << 16) | (0x0000FFFF & -3003), // 没有找到匹配结果 149 | EVRClientErrorCodeServerAppNameUnknownError = (EVRClientErrorDomainServer << 16) | (0x0000FFFF & -3004), // AppnameUnkown错误 150 | EVRClientErrorCodeServerSpeechQualityProblem = (EVRClientErrorDomainServer << 16) | (0x0000FFFF & -3005), // 声音不符合识别要求 151 | EVRClientErrorCodeServerSpeechTooLong = (EVRClientErrorDomainServer << 16) | (0x0000FFFF & -3006), // 语音过长 152 | 153 | EVRClientErrorCodeCommonBusy = (EVRClientErrorDomainCommom << 16) | (0x0000FFFF & 1), // 识别器忙 154 | EVRClientErrorCodeCommonPropertyListInvalid = (EVRClientErrorDomainCommom << 16) | (0x0000FFFF & 2), // 垂类设置有误 155 | EVRClientErrorCodeCommonEnqueueError = (EVRClientErrorDomainCommom << 16) | (0x0000FFFF & 3) // 语音数据enqueue失败 156 | } TVoiceRecognitionClientErrorCode; 157 | 158 | #pragma mark - 调试日志级别 159 | typedef enum TBDVoiceRecognitionDebugLogLevel 160 | { 161 | EVRDebugLogLevelOff = 0, 162 | EVRDebugLogLevelFatal = 1, 163 | EVRDebugLogLevelError = 2, 164 | EVRDebugLogLevelWarning = 3, 165 | EVRDebugLogLevelInformation = 4, 166 | EVRDebugLogLevelDebug = 5, 167 | EVRDebugLogLevelTrace = 6 168 | } TBDVoiceRecognitionDebugLogLevel; 169 | 170 | //HIDEFOROPENPLATFORM_BEGIN 171 | #pragma mark - 语音压缩类型 172 | typedef enum TBDVoiceRecognitionAudioCompressionType 173 | { 174 | EVR_AUDIO_COMPRESSION_MIN = 0, 175 | EVR_AUDIO_COMPRESSION_PCM = 1, 176 | EVR_AUDIO_COMPRESSION_BV32 = 2, 177 | EVR_AUDIO_COMPRESSION_AMR = 3, 178 | EVR_AUDIO_COMPRESSION_MAX = 4, 179 | } TBDVoiceRecognitionAudioCompressionType; 180 | 181 | #pragma mark - 语音识别请求资源类型 182 | typedef enum TBDVoiceRecognitionProtocol 183 | { 184 | EPROTOCOL_DEFAULT = 0, 185 | EPROTOCOL_SEARCH_NBEST = 1, 186 | EPROTOCOL_INPUT_NBEST_PROTOCOL = 2, 187 | EPROTOCOL_POST_PROTOCOL = 101, 188 | EPROTOCOL_WISE_PROTOCOL = 300, 189 | EPROTOCOL_WISE_TEXT_PROTOCOL = 301, 190 | EPROTOCOL_AUDIO_DA_PROTOCOL = 302, 191 | EPROTOCOL_NLU_PROTOCOL = 303, 192 | EPROTOCOL_NLU_TEXT_PROTOCOL = 304, 193 | EPROTOCOL_WISE_NLU_PROTOCOL = 305, 194 | EPROTOCOL_TALK_PROTOCOL = 306, 195 | EPROTOCOL_SEARCH_MUSIC_PROTOCOL = 1000, 196 | } TBDVoiceRecognitionProtocol; 197 | //HIDEFOROPENPLATFORM_END 198 | 199 | #endif /* BDSASRDefines_h */ 200 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/BDSASRParameters.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSASRParameters.h 3 | // BDSpeechClient 4 | // 5 | // Created by baidu on 16/6/6. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #ifndef BDSASRParameters_h 10 | #define BDSASRParameters_h 11 | 12 | #import 13 | 14 | #pragma mark - 开发者身份验证 15 | 16 | /* 17 | * BDS_ASR_API_SECRET_KEYS 18 | * Value explanation: 设置API_KEY and SECRET_KEY 19 | * Value type: NSArray 20 | * Default value: - 21 | */ 22 | extern NSString* BDS_ASR_API_SECRET_KEYS; 23 | 24 | 25 | #pragma mark - 识别器参数配置 26 | 27 | /* 28 | * BDS_ASR_SAMPLE_RATE 29 | * Value explanation: 设置录音采样率,自动模式根据当前网络情况自行调整 30 | * Value type: TVoiceRecognitionRecordSampleRateFlags 31 | * Default value: @(EVoiceRecognitionRecordSampleRate16K) 32 | */ 33 | extern NSString* BDS_ASR_SAMPLE_RATE; 34 | 35 | /* 36 | * BDS_ASR_STRATEGY 37 | * Value explanation: 语音识别策略 38 | * Value type: TBDVoiceRecognitionStrategy 39 | * Default value: @(EVR_STRATEGY_ONLINE) 40 | */ 41 | extern NSString* BDS_ASR_STRATEGY; 42 | 43 | /* 44 | * BDS_ASR_CITY_ID 45 | * Value explanation: 设置城市ID,仅对地图识别类型有效 46 | * Value type: NSInteger 47 | * Default value: @(1)(全国) 48 | */ 49 | extern NSString* BDS_ASR_CITY_ID; 50 | 51 | /* 52 | * BDS_ASR_PROPERTY_LIST 53 | * Value explanation: 设置识别类型列表,输入法不可与其他类型复合 54 | * Value type: NSArray[TBDVoiceRecognitionProperty] 55 | * Default value: @[@(EVoiceRecognitionPropertySearch)] 56 | */ 57 | extern NSString* BDS_ASR_PROPERTY_LIST; 58 | 59 | /* 60 | * BDS_ASR_LANGUAGE 61 | * Value explanation: 设置识别语言 62 | * Value type: TVoiceRecognitionLanguage 63 | * Default value: @(EVoiceRecognitionLanguageChinese) 64 | */ 65 | extern NSString* BDS_ASR_LANGUAGE; 66 | 67 | /* 68 | * BDS_ASR_ENABLE_NLU 69 | * Value explanation: 开启语义解析,将返回包含语义的json串 70 | * Value type: BOOL 71 | * Default value: @(NO) 72 | */ 73 | extern NSString* BDS_ASR_ENABLE_NLU; 74 | 75 | /* 76 | * BDS_ASR_DISABLE_PUNCTUATION 77 | * Value explanation: 关闭输出标点 78 | * Value type: BOOL 79 | * Default value: @(NO) 80 | */ 81 | extern NSString* BDS_ASR_DISABLE_PUNCTUATION; 82 | 83 | /* 84 | * BDS_ASR_ENABLE_CONTACTS 85 | * Value explanation: 开启通讯录识别功能,将优先返回通讯录识别结果,需事先用uploader上传通讯录 86 | * Value type: BOOL 87 | * Default value: @(NO) 88 | */ 89 | extern NSString* BDS_ASR_ENABLE_CONTACTS; 90 | 91 | /* 92 | * BDS_ASR_ENABLE_LOCAL_VAD 93 | * Value explanation: 是否需要对录音数据进行端点检测,如果关闭,请同时关闭服务端提前返回:BDS_ASR_ENABLE_EARLY_RETURN 94 | * Value type: BOOL 95 | * Default value: @(YES) 96 | */ 97 | extern NSString* BDS_ASR_ENABLE_LOCAL_VAD; 98 | 99 | /* 100 | * BDS_ASR_ENABLE_EARLY_RETURN 101 | * Value explanation: 服务端开启提前返回,即允许服务端在未收到客户端发送的结束标志前提前结束识别过程 102 | * Value type: BOOL 103 | * Default value: @(YES) 104 | */ 105 | extern NSString* BDS_ASR_ENABLE_EARLY_RETURN; 106 | 107 | #pragma mark - 音频文件路径(文件识别) 108 | 109 | /* 110 | * BDS_ASR_AUDIO_FILE_PATH 111 | * Value explanation: 设置音频文件路径(数据源) 112 | * Value type: NSString 113 | * Default value: @"" 114 | */ 115 | extern NSString* BDS_ASR_AUDIO_FILE_PATH; 116 | 117 | /* 118 | * BDS_ASR_AUDIO_INPUT_STREAM 119 | * Value explanation: 设置音频输入流(数据源) 120 | * Value type: NSInputStream 121 | * Default value: nil 122 | */ 123 | extern NSString* BDS_ASR_AUDIO_INPUT_STREAM; 124 | 125 | /* 126 | * BDS_ASR_DISABLE_AUDIO_OPERATION 127 | * Value explanation: Disable sdk audio operation (Set audio session disactive). 128 | * Value type: BOOL 129 | * Default value: @(NO) 130 | */ 131 | extern NSString* BDS_ASR_DISABLE_AUDIO_OPERATION; 132 | 133 | #pragma mark - 提示音 134 | 135 | /* 136 | * BDS_ASR_PLAY_TONE 137 | * Value explanation: 识别提示音设置,需添加相应声音文件,可替换 138 | * Value type: TBDVoiceRecognitionPlayTones 139 | * Default value: @(EVRPlayToneNone) (关闭提示音) 140 | */ 141 | extern NSString* BDS_ASR_PLAY_TONE; 142 | 143 | #pragma mark - SDK 工作队列 144 | 145 | /* 146 | * BDS_ASR_WORK_QUEUE 147 | * Value explanation: 指定SDK工作队列 148 | * Value type: dispatch_queue_t 149 | * Default value: main queue (dispatch_get_main_queue()) 150 | * Example: dispatch_queue_create("queueLabel", DISPATCH_QUEUE_SERIAL) 151 | */ 152 | extern NSString* BDS_ASR_WORK_QUEUE; 153 | 154 | #pragma mark - 日志级别 155 | 156 | /* 157 | * BDS_ASR_DEBUG_LOG_LEVEL 158 | * Value explanation: 指定调试日志级别 159 | * Value type: TBDVoiceRecognitionDebugLogLevel 160 | * Default value: @(EVRDebugLogLevelOff) 161 | */ 162 | extern NSString* BDS_ASR_DEBUG_LOG_LEVEL; 163 | 164 | #pragma mark - Offline Engine Verify 165 | 166 | /* 167 | * BDS_ASR_OFFLINE_APP_CODE 168 | * Value explanation: 离线授权所需APPCODE(APPID),如使用该方式进行正式授权,请移除临时授权文件 169 | * Value type: NSString 170 | * Default value: - 171 | */ 172 | extern NSString* BDS_ASR_OFFLINE_APP_CODE; 173 | 174 | /* 175 | * BDS_ASR_OFFLINE_LICENSE_FILE_PATH 176 | * Value explanation: 离线授权文件路径 177 | * Value type: NSString 178 | * Default value: @"" 179 | */ 180 | extern NSString* BDS_ASR_OFFLINE_LICENSE_FILE_PATH; 181 | 182 | 183 | #pragma mark - Offline Engine KWS 184 | 185 | /* 186 | * BDS_ASR_OFFLINE_ENGINE_TYPE 187 | * Value explanation: 离线识别引擎类型 188 | * Value type: TBDVoiceRecognitionOfflineEngineType 189 | * Default value: @(EVR_OFFLINE_ENGINE_GRAMMER) 190 | */ 191 | extern NSString* BDS_ASR_OFFLINE_ENGINE_TYPE; 192 | 193 | /* 194 | * BDS_ASR_OFFLINE_ENGINE_DAT_FILE_PATH 195 | * Value explanation: 离线识别资源文件路径 196 | * Value type: NSString 197 | * Default value: @"" 198 | */ 199 | extern NSString* BDS_ASR_OFFLINE_ENGINE_DAT_FILE_PATH; 200 | 201 | /* 202 | * BDS_ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH 203 | * Value explanation: 离线识别语法文件路径 204 | * Value type: NSString 205 | * Default value: @"" 206 | */ 207 | extern NSString* BDS_ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH; 208 | 209 | /* 210 | * BDS_ASR_OFFLINE_ENGINE_GRAMMER_SLOT 211 | * Value explanation: 语法模式离线语法槽,使用该参数更新离线语法文件 212 | * Value type: NSString (@"{\"name\":[\"张三\",\"李四\"],\"appname\":[\"手白\",\"度秘\"]}") 213 | * Default value: @"" 214 | */ 215 | extern NSString* BDS_ASR_OFFLINE_ENGINE_GRAMMER_SLOT; 216 | 217 | /* 218 | * BDS_ASR_OFFLINE_ENGINE_WAKEUP_WORDS_FILE_PATH 219 | * Value explanation: 唤醒词文件路径,使用了唤醒并使用离线语法识别的情况下需要设置,其他情况请忽略该参数 220 | * Value type: NSString 221 | * Default value: @"" 222 | */ 223 | extern NSString* BDS_ASR_OFFLINE_ENGINE_WAKEUP_WORDS_FILE_PATH; 224 | 225 | #pragma mark - VR from Wakeup 226 | 227 | /* 228 | * BDS_ASR_OFFLINE_ENGINE_TRIGGERED_WAKEUP_WORD 229 | * Value explanation: 当前触发唤醒词,唤醒后立即调用识别的情况下配置,其他情况请忽略该参数 230 | * Value type: NSString 231 | * Default value: @"" 232 | */ 233 | extern NSString* BDS_ASR_OFFLINE_ENGINE_TRIGGERED_WAKEUP_WORD; 234 | 235 | /* 236 | * BDS_ASR_NEED_CACHE_AUDIO 237 | * Value explanation: 唤醒后立刻进行识别需开启该参数,其他情况请忽略该参数 238 | * Value type: BOOL 239 | * Default value: @(NO) 240 | */ 241 | extern NSString* BDS_ASR_NEED_CACHE_AUDIO; 242 | 243 | 244 | #pragma mark - 服务端配置 245 | 246 | /* 247 | * BDS_ASR_PRODUCT_ID 248 | * Value explanation: 设置产品ID 249 | * Value type: NSString 250 | * Default value: - 251 | */ 252 | extern NSString* BDS_ASR_PRODUCT_ID; 253 | 254 | /* 255 | * BDS_ASR_SERVER_URL 256 | * Value explanation: 设置服务器地址 257 | * Value type: NSString 258 | * Default value: - 259 | */ 260 | extern NSString* BDS_ASR_SERVER_URL; 261 | 262 | /* 263 | * BDS_ASR_BROWSER_USER_AGENT 264 | * Value explanation: 设置浏览器标识(Http request header),资源返回时会根据UA适配 265 | * Value type: NSString 266 | * Default value: -(可通过[UIWebView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]获取) 267 | */ 268 | extern NSString* BDS_ASR_BROWSER_USER_AGENT; 269 | 270 | /* 271 | * BDS_ASR_LOCATION 272 | * Value explanation: 更新当前地理位置信息,与地理位置相关的资源会优先返回附近资源信息, 请传入通过GPS获取到的经纬度数据 273 | * Value type: CLLocation 274 | * Default value: - 275 | */ 276 | extern NSString* BDS_ASR_LOCATION; 277 | 278 | 279 | #pragma mark - 识别器扩展配置 280 | 281 | /* 282 | * BDS_ASR_PROTOCOL 283 | * Value explanation: 设置协议类型 284 | * Value type: TBDVoiceRecognitionProtocol 285 | * Default value: @(EPROTOCOL_DEFAULT) 286 | */ 287 | extern NSString* BDS_ASR_PROTOCOL; 288 | 289 | /* 290 | * BDS_ASR_COMPRESSION_TYPE 291 | * Value explanation: 录音数据压缩算法 292 | * Value type: TBDVoiceRecognitionAudioCompressionType 293 | * Default value: @(EVR_AUDIO_COMPRESSION_BV32) 294 | */ 295 | extern NSString* BDS_ASR_COMPRESSION_TYPE; 296 | 297 | /* 298 | * BDS_ASR_ENABLE_DRC 299 | * Value explanation: 是否进行车载环境下的噪声消除 300 | * Value type: BOOL 301 | * Default value: @(NO) 302 | */ 303 | extern NSString* BDS_ASR_ENABLE_DRC; 304 | 305 | 306 | #pragma mark - 扩展参数 307 | 308 | /* 309 | * BDS_ASR_BUA 310 | * Value explanation: 扩展参数,浏览器标识 311 | * Value type: NSString 312 | * Default value: - 313 | */ 314 | extern NSString* BDS_ASR_BUA; 315 | 316 | /* 317 | * BDS_ASR_PAM 318 | * Value explanation: 扩展参数,多轮对话需要的信息 319 | * Value type: NSString 320 | * Default value: - 321 | */ 322 | extern NSString* BDS_ASR_PAM; 323 | 324 | /* 325 | * BDS_ASR_STC 326 | * Value explanation: 扩展参数,统计信息 327 | * Value type: NSString 328 | * Default value: - 329 | */ 330 | extern NSString* BDS_ASR_STC; 331 | 332 | /* 333 | * BDS_ASR_LTP 334 | * Value explanation: 扩展参数,轻应用参数(uid) 335 | * Value type: NSString 336 | * Default value: - 337 | */ 338 | extern NSString* BDS_ASR_LTP; 339 | 340 | /* 341 | * BDS_ASR_TXT 342 | * Value explanation: 扩展参数,上传文本,如果设置了该字段,将略过语音输入和识别阶段(暂不支持) 343 | * Value type: NSString 344 | * Default value: - 345 | */ 346 | extern NSString* BDS_ASR_TXT; 347 | 348 | 349 | #endif /* BDSASRParameters_h */ 350 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/BDSEventManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSEventManager.h 3 | // BDSpeechClient 4 | // 5 | // Created by baidu on 16/6/6. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | extern NSString* BDS_ASR_NAME; 12 | extern NSString* BDS_WAKEUP_NAME; 13 | extern NSString* BDS_UPLOADER_NAME; 14 | 15 | @interface BDSEventManager : NSObject 16 | 17 | + (BDSEventManager *)createEventManagerWithName:(NSString *)name; 18 | - (BOOL)setParameter:(id)param forKey:(NSString *)key; 19 | - (void)sendCommand:(NSString *)command; 20 | - (BOOL)setDelegate:(id)delegate; 21 | - (NSString *)libver; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/BDSUploaderDefines.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSUploaderDefines.h 3 | // BDSpeechClient 4 | // 5 | // Created by baidu on 16/6/6. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #ifndef BDSUploaderDefines_h 10 | #define BDSUploaderDefines_h 11 | 12 | #import 13 | 14 | #pragma mark - Uploader Delegate 15 | @protocol BDSClientUploaderDelegate 16 | - (void)UploadCompleteWithError:(NSError *)error; 17 | @end 18 | 19 | #pragma mark - Uploader Command 20 | extern NSString* BDS_UP_CMD_START; 21 | extern NSString* BDS_UP_CMD_CANCEL; 22 | 23 | #pragma mark - 数据上传错误类别 24 | typedef enum TVoiceRecognitionUploaderErrorDomain 25 | { 26 | EVRUploaderErrorDomain = 100, 27 | } TVoiceRecognitionUploaderErrorDomain; 28 | 29 | #pragma mark - 数据上传错误状态 30 | typedef enum TVoiceRecognitionDataUploaderErrorCode 31 | { 32 | EVRDataUploaderSucceed = (EVRUploaderErrorDomain << 16) | (0x0000FFFF & 0), // 上传成功 33 | EVRDataUploaderParamError = (EVRUploaderErrorDomain << 16) | (0x0000FFFF & 1), // 参数错误 34 | EVRDataUploaderRequestError = (EVRUploaderErrorDomain << 16) | (0x0000FFFF & 2), // 网络请求发生错误 35 | EVRDataUploaderResponseParseError = (EVRUploaderErrorDomain << 16) | (0x0000FFFF & 3), // 服务器数据解析错误 36 | EDataUploaderNetworkUnAvailableError = (EVRUploaderErrorDomain << 16) | (0x0000FFFF & 4), // 网络不可用 37 | } TVoiceRecognitionDataUploaderErrorCode; 38 | 39 | #endif /* BDSUploaderDefines_h */ 40 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/BDSUploaderParameters.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSUploaderParameters.h 3 | // BDSpeechClient 4 | // 5 | // Created by baidu on 16/6/6. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #ifndef BDSUploaderParameters_h 10 | #define BDSUploaderParameters_h 11 | 12 | #import 13 | 14 | /* 15 | * BDS_UPLOADER_SLOT_NAME 16 | * Value explanation: 上传词条名 17 | * Value type: NSString 18 | * Default value: - 19 | */ 20 | extern NSString* BDS_UPLOADER_SLOT_NAME; 21 | 22 | /* 23 | * BDS_UPLOADER_SLOT_WORDS 24 | * Value explanation: 上传词条列表 25 | * Value type: NSArray 26 | * Default value: - 27 | */ 28 | extern NSString* BDS_UPLOADER_SLOT_WORDS; 29 | 30 | #pragma mark - SDK 工作队列 31 | 32 | /* 33 | * BDS_UPLOADER_WORK_QUEUE 34 | * Value explanation: 指定SDK工作队列 35 | * Value type: dispatch_queue_t 36 | * Default value: main queue (dispatch_get_main_queue()) 37 | * Example: dispatch_queue_create("queueLabel", DISPATCH_QUEUE_SERIAL) 38 | */ 39 | extern NSString* BDS_UPLOADER_WORK_QUEUE; 40 | 41 | #endif /* BDSUploaderParameters_h */ 42 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/BDSWakeupDefines.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSWakeupDefines.h 3 | // BDSpeechClient 4 | // 5 | // Created by baidu on 16/6/6. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #ifndef BDSWakeupDefines_h 10 | #define BDSWakeupDefines_h 11 | 12 | #import 13 | 14 | #pragma mark - Wakeup Delegate 15 | @protocol BDSClientWakeupDelegate 16 | - (void)WakeupClientWorkStatus:(int)workStatus obj:(id)aObj; // TWakeupEngineWorkStatus 17 | @end 18 | 19 | #pragma mark - Wakeup Command 20 | extern NSString* BDS_WP_CMD_START; 21 | extern NSString* BDS_WP_CMD_STOP; 22 | extern NSString* BDS_WP_CMD_LOAD_ENGINE; 23 | extern NSString* BDS_WP_CMD_UNLOAD_ENGINE; 24 | 25 | #pragma mark - 唤醒引擎状态 26 | typedef enum TWakeupEngineWorkStatus 27 | { 28 | EWakeupEngineWorkStatusStarted, // 引擎开始工作 29 | EWakeupEngineWorkStatusStopped, // 引擎关闭完成 30 | EWakeupEngineWorkStatusLoaded, // 唤醒引擎加载完成 31 | EWakeupEngineWorkStatusUnLoaded, // 唤醒引擎卸载完成 32 | EWakeupEngineWorkStatusTriggered, // 命中唤醒词 33 | EWakeupEngineWorkStatusError, // 引擎发生错误 34 | } TWakeupEngineWorkStatus; 35 | 36 | #pragma mark - 唤醒引擎错误分类 37 | typedef enum TWakeupEngineErrorDomain 38 | { 39 | EWakeupEngineErrorDomainRecord = 10, // 录音设备出错 40 | EWakeupEngineErrorDomainEngine = 38, // 录音设备出错 41 | } TWakeupEngineErrorDomain; 42 | 43 | #pragma mark - 唤醒引擎错误状态 44 | typedef enum TWakeupEngineErrorCode 45 | { 46 | EWakeupEngineRecoderException = (EWakeupEngineErrorDomainRecord << 16) | (0x0000FFFF & 1), // 录音设备异常 47 | EWakeupEngineRecoderNoPermission = (EWakeupEngineErrorDomainRecord << 16) | (0x0000FFFF & 2), // 无录音权限 48 | EWakeupEngineRecoderUnAvailable = (EWakeupEngineErrorDomainRecord << 16) | (0x0000FFFF & 3), // 录音设备不可用 49 | EWakeupEngineRecoderInterruption = (EWakeupEngineErrorDomainRecord << 16) | (0x0000FFFF & 4), // 录音中断 50 | 51 | EWakeupEngineExceptioin = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 1), // 唤醒引擎异常 52 | EWakeupEngineNoLicense = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 2), // 无授权文件 53 | EWakeupEngineLicenseInvalid = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 3), // 授权文件异常 54 | EWakeupEngineWakeupWordsInvalid = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 4), // 唤醒次异常 55 | EWakeupEngineDatFileInvalid = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 5), // 模型文件异常 56 | EWakeupEngineInitializeFailed = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 6), // 引擎初始化失败 57 | EWakeupEngineAllocMemFailed = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 7), // 内存分配失败 58 | EWakeupEngineResetFailed = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 8), // 引擎重置失败 59 | EWakeupEngineFreeFailed = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 9), // 引擎释放失败 60 | EWakeupEngineArchiNotSupportted = (EWakeupEngineErrorDomainEngine << 16) | (0x0000FFFF & 10), // 引擎不支持该架构 61 | } TWakeupEngineErrorCode; 62 | 63 | #endif /* BDSWakeupDefines_h */ 64 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/BDSWakeupParameters.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSWakeupParameters.h 3 | // BDSpeechClient 4 | // 5 | // Created by baidu on 16/6/6. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #ifndef BDSWakeupParameters_h 10 | #define BDSWakeupParameters_h 11 | 12 | #import 13 | 14 | /* 15 | * BDS_WAKEUP_WORDS 16 | * Value explanation: 唤醒词列表 17 | * Value type: NSArray 18 | * Default value: - 19 | */ 20 | extern NSString* BDS_WAKEUP_WORDS; 21 | 22 | /* 23 | * BDS_WAKEUP_WORDS_FILE_PATH 24 | * Value explanation: 唤醒词文件路径 25 | * Value type: NSString 26 | * Default value: - 27 | */ 28 | extern NSString* BDS_WAKEUP_WORDS_FILE_PATH; 29 | 30 | /* 31 | * BDS_WAKEUP_DAT_FILE_PATH 32 | * Value explanation: 唤醒引擎模型文件路径 33 | * Value type: NSString 34 | * Default value: - 35 | */ 36 | extern NSString* BDS_WAKEUP_DAT_FILE_PATH; 37 | 38 | /* 39 | * BDS_WAKEUP_APP_CODE 40 | * Value explanation: 离线授权所需APPCODE 41 | * Value type: NSString 42 | * Default value: - 43 | */ 44 | extern NSString* BDS_WAKEUP_APP_CODE; 45 | 46 | /* 47 | * BDS_WAKEUP_LICENSE_FILE_PATH 48 | * Value explanation: 离线授权文件路径 49 | * Value type: NSString 50 | * Default value: - 51 | */ 52 | extern NSString* BDS_WAKEUP_LICENSE_FILE_PATH; 53 | 54 | #pragma mark - 音频文件路径(文件识别) 55 | 56 | /* 57 | * BDS_WAKEUP_AUDIO_FILE_PATH 58 | * Value explanation: 设置音频文件路径(数据源) 59 | * Value type: NSString 60 | * Default value: nil 61 | */ 62 | extern NSString* BDS_WAKEUP_AUDIO_FILE_PATH; 63 | 64 | /* 65 | * BDS_WAKEUP_AUDIO_INPUT_STREAM 66 | * Value explanation: 设置音频输入流(数据源) 67 | * Value type: NSInputStream 68 | * Default value: nil 69 | */ 70 | extern NSString* BDS_WAKEUP_AUDIO_INPUT_STREAM; 71 | 72 | /* 73 | * BDS_ASR_DISABLE_AUDIO_OPERATION 74 | * Value explanation: Disable sdk audio operation (Set audio session disactive). 75 | * Value type: BOOL 76 | * Default value: @(NO) 77 | */ 78 | extern NSString* BDS_WAKEUP_DISABLE_AUDIO_OPERATION; 79 | 80 | #pragma mark - SDK 工作队列 81 | 82 | /* 83 | * BDS_WAKEUP_WORK_QUEUE 84 | * Value explanation: 指定SDK工作队列 85 | * Value type: dispatch_queue_t 86 | * Default value: main queue (dispatch_get_main_queue()) 87 | * Example: dispatch_queue_create("queueLabel", DISPATCH_QUEUE_SERIAL) 88 | */ 89 | extern NSString* BDS_WAKEUP_WORK_QUEUE; 90 | 91 | #endif /* BDSWakeupParameters_h */ 92 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/UIHeaders/BDRecognizerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDRecognizerViewController.h 3 | // BDVoiceRecognitionClient 4 | // 5 | // Created by Baidu on 13-9-25. 6 | // Copyright (c) 2013 Baidu Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "BDRecognizerViewDelegate.h" 12 | #import "BDSEventManager.h" 13 | #import "BDSASRDefines.h" 14 | #import "BDRecognizerViewParamsObject.h" 15 | #import "BDTheme.h" 16 | 17 | // 对话框的高度和宽度 18 | extern const float VR_DIALOG_VIEW_WIDTH; 19 | extern const float VR_DIALOG_VIEW_HEIGHT; 20 | 21 | /** 22 | * @brief 语音识别弹窗视图控制类 23 | */ 24 | @interface BDRecognizerViewController : UIViewController 25 | 26 | /** 27 | * @brief 创建弹窗实例 28 | * @param origin 控件左上角的坐标 29 | * @param theme 控件的主题,如果为nil,则为默认主题 30 | * 31 | * @return 弹窗实例 32 | */ 33 | - (id)initRecognizerViewControllerWithOrigin:(CGPoint)origin 34 | theme:(BDTheme *)theme 35 | enableFullScreen:(BOOL)enableFullScreen 36 | paramsObject:(BDRecognizerViewParamsObject *)paramsObject 37 | delegate:(id)delegate; 38 | 39 | /** 40 | * @brief 启动识别 41 | * 42 | */ 43 | - (void)startVoiceRecognition; 44 | 45 | /** 46 | * @brief - 取消本次识别,并移除View 47 | */ 48 | - (void)cancelVoiceRecognition; 49 | 50 | /** 51 | * @brief 屏幕旋转后调用设置识别弹出窗位置 52 | * 53 | */ 54 | - (void)changeFrameAfterOriented:(CGPoint)origin; 55 | 56 | @end // BDRecognizerViewController 57 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/UIHeaders/BDRecognizerViewDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDRecognizerViewDelegate.h 3 | // BDVoiceRecognitionClient 4 | // 5 | // Created by baidu on 13-9-23. 6 | // Copyright (c) 2013年 baidu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class BDRecognizerViewController; 12 | 13 | /** 14 | * @brief - 语音弹窗UI的委托接口 15 | */ 16 | @protocol BDRecognizerViewDelegate 17 | 18 | /** 19 | * @brief 语音识别结果返回,搜索和输入模式结果返回的结构不相同 20 | * 21 | * @param aBDRecognizerView 弹窗UI 22 | * @param aResults 返回结果,原始Json结果 23 | */ 24 | - (void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResult:(id)aResult; 25 | 26 | @optional 27 | /** 28 | * @brief 录音数据返回 29 | * 30 | * @param recordData 录音数据 31 | * @param sampleRate 采样率 32 | */ 33 | - (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate; 34 | 35 | /** 36 | * @brief 录音结束 37 | */ 38 | - (void)onRecordEnded; 39 | 40 | /** 41 | * @brief 返回中间识别结果 42 | * 43 | * @param results: 原始Json结果 44 | */ 45 | - (void)onPartialResult:(id)result; 46 | 47 | /** 48 | * @brief 发生错误 49 | * 50 | * @param errorClass: 错误类别 (TVoiceRecognitionClientErrorStatusClass) 51 | * @param errorCode: 错误码 (TVoiceRecognitionClientErrorStatus) 52 | * @param errDescription: 错误描述 53 | */ 54 | - (void)onError:(int)errClass errCode:(int)errCode errDescription:(NSString *)errDescription; 55 | 56 | /** 57 | * @brief 提示语出现 58 | */ 59 | - (void)onTipsShow; 60 | 61 | /** 62 | * @brief 开始录音 63 | */ 64 | - (void)onRecordStart; 65 | 66 | /** 67 | * @brief 检测到用户开始说话 68 | */ 69 | - (void)onSpeakStart; 70 | 71 | /** 72 | * @brief 检测到用户说话结束 73 | */ 74 | - (void)onSpeakFinish; 75 | 76 | /** 77 | * @brief 识别结束 78 | */ 79 | - (void)onRecogFinish; 80 | 81 | /** 82 | * @brief 用户点击重试 83 | */ 84 | - (void)onRetry; 85 | 86 | /** 87 | * @brief 弹窗关闭 88 | */ 89 | - (void)onClose; 90 | 91 | @end 92 | 93 | /** 94 | * @brief 语音输入弹窗按钮的委托接口,开发者不需要关心 95 | */ 96 | @protocol BDRecognizerDialogDelegate 97 | 98 | @required 99 | - (void)voiceRecognitionDialogHelp; // 出现帮助界面 100 | - (void)voiceRecognitionDialogClosed; // 对话框关闭 101 | - (void)voiceRecognitionDialogRetry; // 用户重试 102 | - (void)voiceRecognitionDialogSpeekFinish; // 说完了 103 | - (NSInteger)currentMeterLevel; // 得到当前音量 104 | 105 | @end // BDRecognizerDialogDelegate 106 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/UIHeaders/BDRecognizerViewParamsObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDRecognizerViewParamsObject.h 3 | // BDVoiceRecognitionClient 4 | // 5 | // Created by Baidu on 13-9-25. 6 | // Copyright (c) 2013年 Baidu, Inc. All rights reserved. 7 | // 8 | 9 | // 头文件 10 | #import 11 | 12 | // 枚举 - 弹窗中连续上屏效果开关 13 | typedef enum 14 | { 15 | BDRecognizerResultShowModeNotShow = 0, // 不显示结果 16 | BDRecognizerResultShowModeWholeShow, // 仅显示最终结果 17 | BDRecognizerResultShowModeContinuousShow, // 提供连续上屏效果(默认) 18 | } TBDRecognizerResultShowMode; 19 | 20 | // @brief - 语音识别弹窗参数配置类 21 | @interface BDRecognizerViewParamsObject : NSObject 22 | 23 | @property (nonatomic, copy) NSString *tipsTitle; // 提示语标题 24 | @property (nonatomic, copy) NSArray *tipsList; // 提示语列表 25 | @property (nonatomic, assign) NSTimeInterval waitTime2ShowTip; // 等待显示提示语的时间 26 | @property (nonatomic, assign) TBDRecognizerResultShowMode resultShowMode; // 显示效果 27 | @property (nonatomic, assign) BOOL isShowTipsOnStart; // 是否在对话框启动后展示引导提示,而不启动识别,默认关闭,若开启,请确认设置提示语列表 28 | @property (nonatomic, assign) BOOL isShowTipAfterSilence; // 引擎启动后一段时间(waitTime2ShowTip)没检测到语音,是否在动效下方随机出现一条提示语。如果配置了提示语列表,则默认开启 29 | @property (nonatomic, assign) BOOL isShowHelpButtonWhenSilence; // 未检测到语音异常时,将“取消”按钮替换成帮助按钮。在配置了提示语列表后,默认开启 30 | @property (nonatomic, assign) BOOL isHidePleaseSpeakSection; // 隐藏“请说话”页 31 | @property (nonatomic, assign) BOOL disableCarousel; // 停用提示语轮播 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/ASR/UIHeaders/BDTheme.h: -------------------------------------------------------------------------------- 1 | // BDTheme.h 2 | // BDVoiceRecognitionClient 3 | // 4 | // Created by Baidu on 13-9-24. 5 | // Copyright 2013 Baidu Inc. All rights reserved. 6 | // 7 | 8 | // 头文件 9 | #import 10 | 11 | @interface BDTheme : NSObject 12 | 13 | @property (nonatomic, copy) NSString *name; 14 | 15 | #pragma mark - 动画面板 16 | @property (nonatomic) NSUInteger visualizerBackgroundColor; //背景颜色 17 | @property (nonatomic) NSUInteger visualizerSquareBackgroundColor; //方块默认颜色 18 | @property (nonatomic) NSUInteger visualizerScanningLineGradientStartColor; //扫描线渐变起始色 19 | @property (nonatomic) NSUInteger visualizerScanningLineGradientEndColor; //扫描线渐变结束色 20 | @property (nonatomic) NSUInteger visualizerSquareGradientStartColor; //方块渐变起始色 21 | @property (nonatomic) NSUInteger visualizerSquareGradientEndColor; //方块渐变结束色 22 | @property (nonatomic) NSUInteger visualizerLogoLightColor; //logo默认颜色 23 | @property (nonatomic) NSUInteger visualizerLogoDarkColor; //logo点亮颜色 24 | 25 | #pragma mark - SDK UI 26 | @property(nonatomic) NSUInteger recognizerViewBackgroundColor; // 背景颜色 27 | @property(nonatomic) NSUInteger dialogBackgroundColor; // 弹窗背景色 28 | @property(nonatomic) NSUInteger dialogErrorColor; // 弹窗错误文案颜色 29 | @property(nonatomic) NSUInteger dialogTitleAndResultColor; // 提示文字和识别结果颜色 30 | @property(nonatomic) NSUInteger dialogOtherButtonColor; // 除重试按钮文字颜色 31 | @property(nonatomic) NSUInteger dialogRetryButtonColor; // 按钮文字颜色 32 | @property(nonatomic) NSUInteger dialogRecognizingColor; // 识别中按钮文字颜色 33 | @property(nonatomic) NSUInteger dialogFinishButtonColor; // 完成按钮文字颜色 34 | @property(nonatomic) NSUInteger dialogBaiduFlagColor; // 按钮文字颜色 35 | @property(nonatomic) NSUInteger dialogConfirmedTitleColor; 36 | @property(nonatomic) NSUInteger dialogInnerBorderColor; 37 | @property(nonatomic) NSUInteger dialogOuterBorderColor; 38 | 39 | + (instancetype)defaultTheme; //默认主题 40 | + (instancetype)defaultFullScreenTheme; //默认全屏主题 41 | + (instancetype)lightBlueTheme; //亮蓝主题 42 | + (instancetype)darkBlueTheme; //暗蓝主题 43 | + (instancetype)lightGreenTheme; //亮绿主题 44 | + (instancetype)darkGreenTheme; //暗绿主题 45 | + (instancetype)lightOrangeTheme; //亮橙主题 46 | + (instancetype)darkOrangeTheme; //暗橙主题 47 | + (instancetype)lightRedTheme; //亮红主题 48 | + (instancetype)darkRedTheme; //暗红主题 49 | 50 | - (NSString *)pathForResource:(NSString *)name ofType:(NSString *)type; 51 | 52 | @end -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/TTS/BDSBuiltInPlayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSBuiltInPlayer.h 3 | // BDSSpeechSynthesizer 4 | // 5 | // Created by 段弘 on 14-7-14. 6 | // Copyright (c) 2014年 百度. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class BDSBuiltInPlayer; 12 | 13 | @protocol BDSBuiltInPlayerDelegate 14 | 15 | /** 16 | * @brief 播放已结束 17 | * 18 | * @param player 播放器对象 19 | */ 20 | - (void)playerDidFinished:(BDSBuiltInPlayer *)player; 21 | 22 | /** 23 | * @brief 播放被暂停(被其他应用程序中断) 24 | * 25 | * @param player 播放器对象 26 | */ 27 | - (void)playerDidPaused:(BDSBuiltInPlayer *)player; 28 | 29 | /** 30 | * @brief 播放器发生错误,请重新建立播放器对象 31 | * 32 | * @param player 33 | * 播放器对象 34 | * @param error 35 | * 错误信息 36 | */ 37 | - (void)playerErrorOccured:(BDSBuiltInPlayer *)player error:(NSError*)error; 38 | 39 | @end 40 | 41 | @interface BDSBuiltInPlayer : NSObject 42 | 43 | /** 播放器状态代理 */ 44 | @property (nonatomic, weak) id delegate; 45 | 46 | /** AudioSessionCategory类型,取值参见AVAudioSession Class Reference */ 47 | @property (nonatomic, copy) NSString *audioSessionCategory; 48 | 49 | /** 50 | * @brief 播放音频数据,仅支持播放由合成器返回的pcm数据 51 | * 52 | * @param data 53 | * pcm数据 54 | * @param outError 55 | * 如果播放失败,该对象将用于返回错误信息 56 | */ 57 | - (BOOL)playPcmData:(NSData *)data error:(NSError **)outError; 58 | 59 | /** 60 | * @brief 播放URL所指向的内容 61 | * 62 | * @param url 63 | * 用于指定需要播放的音频文件 64 | * @param outError 65 | * 如果播放失败,该对象将用于返回错误信息 66 | */ 67 | - (BOOL)playContentsOfURL:(NSURL *)url error:(NSError **)outError; 68 | 69 | /** 70 | * @brief 暂停播放 71 | */ 72 | - (void)pause; 73 | 74 | /** 75 | * @brief 继续播放 76 | */ 77 | - (void)resume; 78 | 79 | /** 80 | * @brief 停止播放 81 | */ 82 | - (void)stop; 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/TTS/BDSMixedModeSynthesizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSMixedModeSynthesizer.h 3 | // BDSSpeechSynthesizer 4 | // 5 | // Created by lappi on 4/14/15. 6 | // Copyright (c) 2015 百度. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BDSSpeechSynthesizerDelegate.h" 11 | #import "BDSSynthesizerLogLevel.h" 12 | #import "BDSSpeechSynthesizerParams.h" 13 | #import "BDSSpeechSynthesizerErrors.h" 14 | 15 | @interface BDSSpeechSynthesizer : NSObject 16 | 17 | /** TTS播报的category */ 18 | @property (nonatomic, copy) NSString *audioSessionCategory; 19 | 20 | #pragma mark - Init/Uninit 21 | /** 22 | * @brief 获取合成器唯一实例 23 | * 24 | * @return 返回合成器唯一实例 25 | */ 26 | + (BDSSpeechSynthesizer*)sharedInstance; 27 | 28 | /** 29 | * @brief 释放合成器唯一实例 30 | * 31 | * 32 | */ 33 | + (void)releaseInstance; 34 | 35 | #pragma mark - Configurations 36 | 37 | /** 38 | * @brief 设置合成器代理 39 | * 40 | * @param delegate 代理对象,负责处理合成器各类事件 41 | * 42 | * @return 识别器对象 43 | */ 44 | - (void)setSynthesizerDelegate: (id)delegate; 45 | 46 | /* 47 | * @brief set synthesizer param 48 | * @param param Parameter object. Refer to enum BDSSynthesizerParamKey for object types and valid values for different keys. 49 | * @param key Key for parameter. 50 | * 51 | */ 52 | -(NSError*)setSynthParam:(id)param forKey:(BDSSynthesizerParamKey)key; 53 | 54 | /* 55 | * @brief get current value of parameter 56 | * @param key Key for parameter. 57 | * @param err If not nil, is set to BDS_SYNTHESIZER_PARAM_ERR_OK on success or error code on failure. 58 | * @return parameter object or nil. Refer to enum BDSSynthesizerParamKey for object types for different keys. 59 | */ 60 | -(id)getSynthParamforKey:(BDSSynthesizerParamKey)key withError:(NSError**)err; 61 | 62 | /** 63 | * @brief 设置认证信息 64 | * 65 | * @param apiKey 在百度开发者中心注册应用获得 66 | * @param secretKey 在百度开发者中心注册应用获得 67 | */ 68 | - (void)setApiKey:(NSString *)apiKey withSecretKey:(NSString *)secretKey; 69 | 70 | /** 71 | * -(NSError*)setSDKCallbackQueue:(dispatch_queue_t)callbackQueue; 72 | * @brief YOU CAN IGNORE THIS IF YOU ARE GOING TO USE THIS SDK DIRECTLY FROM UI THREAD. 73 | * Sets the queue that should be used for making callbacks to BDSSpeechSynthesizerDelegate. 74 | * By default UI queue is used. 75 | * 76 | * @param callbackQueue A serial queue for making callbacks. (Using concurrent queue may result in 77 | * unexpected behaviour in some cases) 78 | * 79 | * @sample [[BDSSpeechSynthesizer sharedInstance] setSDKCallbackQueue:dispatch_queue_create("MY_CALLBACK", DISPATCH_QUEUE_SERIAL)]; 80 | * 81 | * @return nil On success. 82 | * 83 | */ 84 | -(NSError*)setSDKCallbackQueue:(dispatch_queue_t)callbackQueue; 85 | 86 | /** 87 | * -(dispatch_queue_t)getCurrentCallbackQueue 88 | * @brief YOU CAN IGNORE THIS IF YOU ARE GOING TO USE THIS SDK DIRECTLY FROM UI THREAD. 89 | * Gets current dispatch queue used for callbacks. 90 | * It is recommended to use returned queue to call other interface methods of this SDK. 91 | * Calling from other queues/thread may result in unexpected behaviour in some cases. 92 | * By default this is UI queue. 93 | */ 94 | -(dispatch_queue_t)getCurrentCallbackQueue; 95 | #pragma mark - Load Embedded TTS engine 96 | 97 | /** 98 | * @brief 启动合成引擎 99 | * 100 | * @param textDatFilePath 文本分析数据文件路径 101 | * @param speechDataPath 声学模型数据文件路径 102 | * @param licenseFilePath 授权文件路径,如果没有本地授权可传入nil 103 | * @param appCode 用户持有的授权app code 104 | * 105 | * @return 错误码, nil on success 106 | */ 107 | - (NSError*)loadOfflineEngine: (NSString*)textDatFilePath 108 | speechDataPath: (NSString*)speechDatFilePath 109 | licenseFilePath: (NSString*)licenseFilePath 110 | withAppCode: (NSString*)appCode; 111 | 112 | -(NSError*)loadEnglishDataForOfflineEngine: (NSString*)textDataPath 113 | speechData: (NSString*)speechDataPath; 114 | 115 | /** 116 | * @brief 重新加载文本分析数据文件或者声学模型数据文件 117 | * 118 | * @param datFilePath: 数据文件路径 119 | * 120 | * @return 错误码, nil on success 121 | */ 122 | - (NSError*)reinitOfflineEngineData: (NSString*)datFilePath; 123 | 124 | /** 125 | * @brief 加载定制库,在loadOfflineEngine:licenseFilePath:withAppCode:消息被调用后,调用此函数 126 | * 127 | * @param datFilePath 定制库路径 128 | * 129 | * @return 错误码, nil on success 130 | */ 131 | - (NSError*)loadDomainDataForOfflineEngine:(NSString*)datFilePath; 132 | 133 | /** 134 | * @brief 卸载定制库 135 | * 136 | * @return 错误码, nil on success 137 | */ 138 | - (NSError*)unloadDomainDataFromOfflineEngine; 139 | 140 | /** 141 | * @brief 验证音库文件的有效性 142 | * @param datFilePath data文件路径 143 | * @param err 如果验证失败, 返回错误信息 144 | * 145 | * @return 验证成功YES,失败NO 146 | */ 147 | - (BOOL)verifyDataFile: (NSString*) datFilePath error:(NSError**)err; 148 | 149 | /** 150 | * @brief 获取音库文件相关参数 151 | * @param datFilePath data文件路径 152 | * @param paramType 参数类型 153 | * @param paramValue 传出对应参数的值 154 | * @param err 如果失败, 返回错误信息 155 | * 156 | * @return 成功YES,失败NO 157 | */ 158 | - (BOOL)getDataFileParam: (NSString*)datFilePath 159 | type: (TTSDataParam)paramType 160 | value: (NSString**)paramValue 161 | error: (NSError**)err; 162 | 163 | #pragma mark - Synthesis interfaces 164 | /* 165 | * @brief Synthesize and speak text 166 | * @param sentence Text to be spoken. 167 | * @param err Will contain error details on return if something went wrong. 168 | * @return Sentence ID number or -1. If -1 is returned, check content of err to get error details 169 | * 170 | * To speak multiple sentences this interface can be called repeatedly, passed texts will be queued. 171 | * Will fail with "busy error" if there is are ongoing tasks started with synthesizeSentence:withError:. 172 | */ 173 | -(NSInteger) speakSentence:(NSString*)sentence withError:(NSError**)err; 174 | 175 | /* 176 | * @brief Synthesize text without speaking 177 | * @param sentence Text to be synthesized. 178 | * @param err Will contain error details on return if something went wrong. 179 | * @return Sentence ID number or -1. If -1 is returned, check content of err to get error details 180 | * 181 | * To synthesize multiple sentences this interface can be called repeatedly, passed texts will be queued. 182 | * Will fail with "busy error" if there is are ongoing tasks started with speakSentence:withError:. 183 | */ 184 | -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err; 185 | 186 | /** 187 | * @brief 取消本次合成并停止朗读 188 | */ 189 | - (void)cancel; 190 | 191 | /** 192 | * @brief 暂停文本合成并朗读 193 | */ 194 | - (BDSSynthesizerStatus)pause __attribute__((deprecated("The return type of this interface will be changed to void in near future, ignore the returned value and use - (BDSSynthesizerStatus)synthesizerStatus to check status if needed"))); 195 | 196 | /** 197 | * @brief 继续文本合成并朗读 198 | */ 199 | - (BDSSynthesizerStatus)resume __attribute__((deprecated("The return type of this interface will be changed to void in near future, ignore the returned value and use - (BDSSynthesizerStatus)synthesizerStatus to check status if needed"))); 200 | 201 | /** 202 | * @brief 获取合成器状态 203 | * 204 | */ 205 | - (BDSSynthesizerStatus)synthesizerStatus; 206 | 207 | /** 208 | * @brief return total count of sentences queued for playback 209 | * the count also includes sentences that haven't been synthesized yet. 210 | */ 211 | -(NSInteger)RemainingPlaybackSentenceCount; 212 | 213 | /** 214 | * @brief return total count of sentences that are still to be synthesized. 215 | */ 216 | -(NSInteger)RemainingSynthesizeSentenceCount; 217 | 218 | #pragma mark - Playback control 219 | 220 | /** 221 | * @brief 设置播放器音量 222 | * 223 | * @param volume 音量值 224 | * 225 | */ 226 | - (void)setPlayerVolume:(float)volume; 227 | 228 | /** 229 | * @brief 设置AudioSessionCategory类型 230 | * 231 | * @param category AudioSessionCategory类型,取值参见AVAudioSession Class Reference 232 | * Note: BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT must be set to YES for this to have effect. 233 | * 234 | * Default: AVAudioSessionCategoryPlayback 235 | */ 236 | - (void)setAudioSessionCategory:(NSString *)category; 237 | 238 | #pragma mark - Debugging 239 | 240 | /** 241 | * @brief 设置日志级别 242 | * 243 | * @param logLevel 日志级别 244 | */ 245 | + (void)setLogLevel:(BDSLogLevel)logLevel; 246 | 247 | /** 248 | * @brief 获取当前日志级别 249 | * 250 | * @return 日志级别 251 | */ 252 | + (BDSLogLevel)logLevel; 253 | 254 | /** 255 | * @brief 获取库版本号 256 | * 257 | * @return 版本号 258 | */ 259 | + (NSString *)version; 260 | 261 | /** 262 | * @brief 获取引擎版本信息 263 | * 264 | */ 265 | + (NSInteger)engineVersion; 266 | 267 | - (NSString*)offlineEngineVersion:(NSError**)err; 268 | 269 | #pragma mark - Deprecated interfaces 270 | 271 | /* 272 | * @brief set synthesizer param 273 | * @param param Parameter object. Refer to enum BDSSynthesizerParamKey for object types and valid values for different keys. 274 | * @param key Key for parameter. 275 | * 276 | */ 277 | -(BDSSynthesizerParamError)setSynthesizerParam:(id)param forKey:(BDSSynthesizerParamKey)key __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSError*)setSynthParam:(id)param forKey:(BDSSynthesizerParamKey)key"))); 278 | 279 | /* 280 | * @brief get current value of parameter 281 | * @param key Key for parameter. 282 | * @param err If not nil, is set to BDS_SYNTHESIZER_PARAM_ERR_OK on success or error code on failure. 283 | * @return parameter object or nil. Refer to enum BDSSynthesizerParamKey for object types for different keys. 284 | */ 285 | -(id)getSynthesizerParamforKey:(BDSSynthesizerParamKey)key error:(BDSSynthesizerParamError*)err __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(id)getSynthParamforKey:(BDSSynthesizerParamKey)key withError:(NSError**)err"))); 286 | 287 | /** 288 | * -(BDSSynthesizerParamError)setCallbackQueue:(dispatch_queue_t)callbackQueue; 289 | * @brief YOU CAN IGNORE THIS IF YOU ARE GOING TO USE THIS SDK DIRECTLY FROM UI THREAD. 290 | * Sets the queue that should be used for making callbacks to BDSSpeechSynthesizerDelegate. 291 | * By default UI queue is used. 292 | * 293 | * @param callbackQueue A serial queue for making callbacks. (Using concurrent queue may result in 294 | * unexpected behaviour in some cases) 295 | * 296 | * @sample [[BDSSpeechSynthesizer sharedInstance] setCallbackQueue:dispatch_queue_create("MY_CALLBACK", DISPATCH_QUEUE_SERIAL)]; 297 | * 298 | * @return BDS_SYNTHESIZER_PARAM_ERR_OK On success. 299 | * BDS_SYNTHESIZER_PARAM_ERR_SDK_BUSY If synthesis is running. 300 | * BDS_SYNTHESIZER_PARAM_ERR_SDK_UNINIT If SDK is not properly initialized. 301 | * 302 | */ 303 | -(BDSSynthesizerParamError)setCallbackQueue:(dispatch_queue_t)callbackQueue __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSError*)setSDKCallbackQueue:(dispatch_queue_t)callbackQueue"))); 304 | 305 | /** 306 | * @brief 启动合成引擎 307 | * 308 | * @param textDatFilePath 文本分析数据文件路径 309 | * @param speechDataPath 声学模型数据文件路径 310 | * @param licenseFilePath 授权文件路径,如果没有本地授权可传入nil 311 | * @param appCode 用户持有的授权app code 312 | * 313 | * @return 错误码 314 | */ 315 | - (BDSErrEngine)startTTSEngine: (NSString*)textDatFilePath 316 | speechDataPath: (NSString*)speechDatFilePath 317 | licenseFilePath: (NSString*)licenseFilePath 318 | withAppCode: (NSString*)appCode __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)loadOfflineEngine:speechDataPath:licenseFilePath:withAppCode:"))); 319 | 320 | -(BDSErrEngine)loadEnglishData: (NSString*)textDataPath 321 | speechData: (NSString*)speechDataPath __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)loadEnglishDataForOfflineEngine:speechData:"))); 322 | 323 | 324 | /** 325 | * @brief 重新加载文本分析数据文件或者声学模型数据文件 326 | * 327 | * @param datFilePath: 数据文件路径 328 | * 329 | * @return 错误码 330 | */ 331 | - (BDSErrEngine)reinitTTSData: (NSString*)datFilePath __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)reinitOfflineEngineData:(NSString*)datFilePath"))); 332 | 333 | /** 334 | * @brief 加载定制库,在startTTSEngine:licenseFilePath:withAppCode:消息被调用后,调用此函数 335 | * 336 | * @param datFilePath 定制库路径 337 | * 338 | * @return 错误码 339 | */ 340 | - (BDSErrEngine)loadDomainData:(NSString*)datFilePath __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)loadDomainDataForOfflineEngine:(NSString*)datFilePath"))); 341 | 342 | /** 343 | * @brief 卸载定制库 344 | * 345 | * @return 错误码 346 | */ 347 | - (BDSErrEngine)unloadDomainData __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)unloadDomainDataFromOfflineEngine"))); 348 | 349 | /** 350 | * @brief 开始文本合成但不朗读,开发者需要通过BDSSpeechSynthesizerDelegate的 351 | * synthesizerNewDataArrived:data:isLastData:sentenceNumber:方法传回的数据自行播放 352 | * The sentence number passed to callbacks will be 0 353 | * 354 | * @param text 需要语音合成的文本 355 | */ 356 | - (BDSStartSynthesisError)synthesize:(NSString *)text __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err"))); 357 | 358 | /** 359 | * @brief 开始文本合成但不朗读,开发者需要通过BDSSpeechSynthesizerDelegate的 360 | * synthesizerNewDataArrived:data:isLastData:sentenceNumber:方法传回的数据自行播放 361 | * 362 | * @param strings 需要语音合成的文本 363 | * The sentence number passed to callbacks indicates the index of string in this array. 364 | */ 365 | -(BDSStartSynthesisError)batchSynthesize:(NSArray *)strings __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err"))); 366 | 367 | /** 368 | * @brief 开始文本合成并朗读 369 | * The sentence number passed to callbacks will be 0 370 | * 371 | * @param text 需要朗读的文本 372 | */ 373 | - (BDSStartSynthesisError)speak:(NSString *)text __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) speakSentence:(NSString*)sentence withError:(NSError**)err"))); 374 | 375 | /** 376 | * @brief 开始文本合成并朗读 377 | * 378 | * @param strings 需要朗读的文本 379 | * The sentence number passed to callbacks indicates the index of string in this array. 380 | */ 381 | - (BDSStartSynthesisError)batchSpeak:(NSArray*)strings __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) speakSentence:(NSString*)sentence withError:(NSError**)err"))); 382 | 383 | /** 384 | * @brief Start new speak task with sentences or add more sentences to current playback 385 | * 386 | * @param sentences Array of sentences to be added. 387 | * @param generatedIDs Empty mutable array, on return contains array of NSNumber objects indicating 388 | * IDs for passed sentences. If passed array is not empty, generated IDs will be 389 | * added to the end of the array. 390 | * The returned IDs corresbond to the SynthesizeSentence- and SpeakSentence- 391 | * parameters passed to BDSSpeechSynthesizerDelegate's callback methods. 392 | * 393 | * @note The ID is a running number which is initially 0 and increases by one for each sentence 394 | * passed here. The number gets reset to 0 when old synthesize-, batchSynthesize-, speak- 395 | * and batchSpeak-interfaces are used. This is to maintain backward compatibility of the SDK. 396 | * 397 | * @return Error code. If != BDS_START_SYNTHESIS_OK, no sentences have been added and generatedIDs is unchanged. 398 | */ 399 | - (BDSStartSynthesisError)queueSpeakSentences:(NSArray*)sentences sentenceIDs:(NSMutableArray*)generatedIDs __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) speakSentence:(NSString*)sentence withError:(NSError**)err"))); 400 | 401 | /** 402 | * @brief Start new synthesis task with sentences or add more sentences to current synthesis 403 | * 404 | * @param sentences Array of sentences to be added. 405 | * @param generatedIDs Empty mutable array, on return contains array of NSNumber objects indicating 406 | * IDs for passed sentences. If passed array is not empty, generated IDs will be 407 | * added to the end of the array. 408 | * The returned IDs corresbond to the SynthesizeSentence- and SpeakSentence- 409 | * parameters passed to BDSSpeechSynthesizerDelegate's callback methods. 410 | * 411 | * @note The ID is a running number which is initially 0 and increases by one for each sentence 412 | * passed here. The number gets reset to 0 when old synthesize-, batchSynthesize-, speak- 413 | * and batchSpeak-interfaces are used. This is to maintain backward compatibility of the SDK. 414 | * 415 | * @return Error code. If != BDS_START_SYNTHESIS_OK, no sentences have been added and generatedIDs is unchanged. 416 | */ 417 | - (BDSStartSynthesisError)queueSynthesizeSentences:(NSArray*)sentences sentenceIDs:(NSMutableArray*)generatedIDs __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err"))); 418 | 419 | /** 420 | * @brief 获取错误码对应的描述 421 | * 422 | * @param errorCode 错误码 423 | * 424 | * @return 错误描述信息 425 | */ 426 | - (NSString *)errorDescriptionForCode:(NSInteger)errorCode __attribute__((deprecated("This interface has been scheduled for removal in near future. All new interfaces will begin returning NSError objects that already contain description"))); 427 | 428 | @end -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSpeechSynthesizer.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSMixedModeSynthesizer.h 3 | // BDSSpeechSynthesizer 4 | // 5 | // Created by lappi on 4/14/15. 6 | // Copyright (c) 2015 百度. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BDSSpeechSynthesizerDelegate.h" 11 | #import "BDSSynthesizerLogLevel.h" 12 | #import "BDSSpeechSynthesizerParams.h" 13 | #import "BDSSpeechSynthesizerErrors.h" 14 | 15 | @interface BDSSpeechSynthesizer : NSObject 16 | 17 | /** TTS播报的category */ 18 | @property (nonatomic, copy) NSString *audioSessionCategory; 19 | 20 | #pragma mark - Init/Uninit 21 | /** 22 | * @brief 获取合成器唯一实例 23 | * 24 | * @return 返回合成器唯一实例 25 | */ 26 | + (BDSSpeechSynthesizer*)sharedInstance; 27 | 28 | /** 29 | * @brief 释放合成器唯一实例 30 | * 31 | * 32 | */ 33 | + (void)releaseInstance; 34 | 35 | #pragma mark - Configurations 36 | 37 | /** 38 | * @brief 设置合成器代理 39 | * 40 | * @param delegate 代理对象,负责处理合成器各类事件 41 | * 42 | * @return 识别器对象 43 | */ 44 | - (void)setSynthesizerDelegate: (id)delegate; 45 | 46 | /* 47 | * @brief set synthesizer param 48 | * @param param Parameter object. Refer to enum BDSSynthesizerParamKey for object types and valid values for different keys. 49 | * @param key Key for parameter. 50 | * 51 | */ 52 | -(NSError*)setSynthParam:(id)param forKey:(BDSSynthesizerParamKey)key; 53 | 54 | /* 55 | * @brief get current value of parameter 56 | * @param key Key for parameter. 57 | * @param err If not nil, is set to BDS_SYNTHESIZER_PARAM_ERR_OK on success or error code on failure. 58 | * @return parameter object or nil. Refer to enum BDSSynthesizerParamKey for object types for different keys. 59 | */ 60 | -(id)getSynthParamforKey:(BDSSynthesizerParamKey)key withError:(NSError**)err; 61 | 62 | /** 63 | * @brief 设置认证信息 64 | * 65 | * @param apiKey 在百度开发者中心注册应用获得 66 | * @param secretKey 在百度开发者中心注册应用获得 67 | */ 68 | - (void)setApiKey:(NSString *)apiKey withSecretKey:(NSString *)secretKey; 69 | 70 | /** 71 | * -(NSError*)setSDKCallbackQueue:(dispatch_queue_t)callbackQueue; 72 | * @brief YOU CAN IGNORE THIS IF YOU ARE GOING TO USE THIS SDK DIRECTLY FROM UI THREAD. 73 | * Sets the queue that should be used for making callbacks to BDSSpeechSynthesizerDelegate. 74 | * By default UI queue is used. 75 | * 76 | * @param callbackQueue A serial queue for making callbacks. (Using concurrent queue may result in 77 | * unexpected behaviour in some cases) 78 | * 79 | * @sample [[BDSSpeechSynthesizer sharedInstance] setSDKCallbackQueue:dispatch_queue_create("MY_CALLBACK", DISPATCH_QUEUE_SERIAL)]; 80 | * 81 | * @return nil On success. 82 | * 83 | */ 84 | -(NSError*)setSDKCallbackQueue:(dispatch_queue_t)callbackQueue; 85 | 86 | /** 87 | * -(dispatch_queue_t)getCurrentCallbackQueue 88 | * @brief YOU CAN IGNORE THIS IF YOU ARE GOING TO USE THIS SDK DIRECTLY FROM UI THREAD. 89 | * Gets current dispatch queue used for callbacks. 90 | * It is recommended to use returned queue to call other interface methods of this SDK. 91 | * Calling from other queues/thread may result in unexpected behaviour in some cases. 92 | * By default this is UI queue. 93 | */ 94 | -(dispatch_queue_t)getCurrentCallbackQueue; 95 | #pragma mark - Load Embedded TTS engine 96 | 97 | /** 98 | * @brief 启动合成引擎 99 | * 100 | * @param textDatFilePath 文本分析数据文件路径 101 | * @param speechDataPath 声学模型数据文件路径 102 | * @param licenseFilePath 授权文件路径,如果没有本地授权可传入nil 103 | * @param appCode 用户持有的授权app code 104 | * 105 | * @return 错误码, nil on success 106 | */ 107 | - (NSError*)loadOfflineEngine: (NSString*)textDatFilePath 108 | speechDataPath: (NSString*)speechDatFilePath 109 | licenseFilePath: (NSString*)licenseFilePath 110 | withAppCode: (NSString*)appCode; 111 | 112 | -(NSError*)loadEnglishDataForOfflineEngine: (NSString*)textDataPath 113 | speechData: (NSString*)speechDataPath; 114 | 115 | /** 116 | * @brief 重新加载文本分析数据文件或者声学模型数据文件 117 | * 118 | * @param datFilePath: 数据文件路径 119 | * 120 | * @return 错误码, nil on success 121 | */ 122 | - (NSError*)reinitOfflineEngineData: (NSString*)datFilePath; 123 | 124 | /** 125 | * @brief 加载定制库,在loadOfflineEngine:licenseFilePath:withAppCode:消息被调用后,调用此函数 126 | * 127 | * @param datFilePath 定制库路径 128 | * 129 | * @return 错误码, nil on success 130 | */ 131 | - (NSError*)loadDomainDataForOfflineEngine:(NSString*)datFilePath; 132 | 133 | /** 134 | * @brief 卸载定制库 135 | * 136 | * @return 错误码, nil on success 137 | */ 138 | - (NSError*)unloadDomainDataFromOfflineEngine; 139 | 140 | /** 141 | * @brief 验证音库文件的有效性 142 | * @param datFilePath data文件路径 143 | * @param err 如果验证失败, 返回错误信息 144 | * 145 | * @return 验证成功YES,失败NO 146 | */ 147 | - (BOOL)verifyDataFile: (NSString*) datFilePath error:(NSError**)err; 148 | 149 | /** 150 | * @brief 获取音库文件相关参数 151 | * @param datFilePath data文件路径 152 | * @param paramType 参数类型 153 | * @param paramValue 传出对应参数的值 154 | * @param err 如果失败, 返回错误信息 155 | * 156 | * @return 成功YES,失败NO 157 | */ 158 | - (BOOL)getDataFileParam: (NSString*)datFilePath 159 | type: (TTSDataParam)paramType 160 | value: (NSString**)paramValue 161 | error: (NSError**)err; 162 | 163 | #pragma mark - Synthesis interfaces 164 | /* 165 | * @brief Synthesize and speak text 166 | * @param sentence Text to be spoken. 167 | * @param err Will contain error details on return if something went wrong. 168 | * @return Sentence ID number or -1. If -1 is returned, check content of err to get error details 169 | * 170 | * To speak multiple sentences this interface can be called repeatedly, passed texts will be queued. 171 | * Will fail with "busy error" if there is are ongoing tasks started with synthesizeSentence:withError:. 172 | */ 173 | -(NSInteger) speakSentence:(NSString*)sentence withError:(NSError**)err; 174 | 175 | /* 176 | * @brief Synthesize text without speaking 177 | * @param sentence Text to be synthesized. 178 | * @param err Will contain error details on return if something went wrong. 179 | * @return Sentence ID number or -1. If -1 is returned, check content of err to get error details 180 | * 181 | * To synthesize multiple sentences this interface can be called repeatedly, passed texts will be queued. 182 | * Will fail with "busy error" if there is are ongoing tasks started with speakSentence:withError:. 183 | */ 184 | -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err; 185 | 186 | /** 187 | * @brief 取消本次合成并停止朗读 188 | */ 189 | - (void)cancel; 190 | 191 | /** 192 | * @brief 暂停文本合成并朗读 193 | */ 194 | - (BDSSynthesizerStatus)pause __attribute__((deprecated("The return type of this interface will be changed to void in near future, ignore the returned value and use - (BDSSynthesizerStatus)synthesizerStatus to check status if needed"))); 195 | 196 | /** 197 | * @brief 继续文本合成并朗读 198 | */ 199 | - (BDSSynthesizerStatus)resume __attribute__((deprecated("The return type of this interface will be changed to void in near future, ignore the returned value and use - (BDSSynthesizerStatus)synthesizerStatus to check status if needed"))); 200 | 201 | /** 202 | * @brief 获取合成器状态 203 | * 204 | */ 205 | - (BDSSynthesizerStatus)synthesizerStatus; 206 | 207 | /** 208 | * @brief return total count of sentences queued for playback 209 | * the count also includes sentences that haven't been synthesized yet. 210 | */ 211 | -(NSInteger)RemainingPlaybackSentenceCount; 212 | 213 | /** 214 | * @brief return total count of sentences that are still to be synthesized. 215 | */ 216 | -(NSInteger)RemainingSynthesizeSentenceCount; 217 | 218 | #pragma mark - Playback control 219 | 220 | /** 221 | * @brief 设置播放器音量 222 | * 223 | * @param volume 音量值 224 | * 225 | */ 226 | - (void)setPlayerVolume:(float)volume; 227 | 228 | /** 229 | * @brief 设置AudioSessionCategory类型 230 | * 231 | * @param category AudioSessionCategory类型,取值参见AVAudioSession Class Reference 232 | * Note: BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT must be set to YES for this to have effect. 233 | * 234 | * Default: AVAudioSessionCategoryPlayback 235 | */ 236 | - (void)setAudioSessionCategory:(NSString *)category; 237 | 238 | #pragma mark - Debugging 239 | 240 | /** 241 | * @brief 设置日志级别 242 | * 243 | * @param logLevel 日志级别 244 | */ 245 | + (void)setLogLevel:(BDSLogLevel)logLevel; 246 | 247 | /** 248 | * @brief 获取当前日志级别 249 | * 250 | * @return 日志级别 251 | */ 252 | + (BDSLogLevel)logLevel; 253 | 254 | /** 255 | * @brief 获取库版本号 256 | * 257 | * @return 版本号 258 | */ 259 | + (NSString *)version; 260 | 261 | /** 262 | * @brief 获取引擎版本信息 263 | * 264 | */ 265 | + (NSInteger)engineVersion; 266 | 267 | - (NSString*)offlineEngineVersion:(NSError**)err; 268 | 269 | #pragma mark - Deprecated interfaces 270 | 271 | /* 272 | * @brief set synthesizer param 273 | * @param param Parameter object. Refer to enum BDSSynthesizerParamKey for object types and valid values for different keys. 274 | * @param key Key for parameter. 275 | * 276 | */ 277 | -(BDSSynthesizerParamError)setSynthesizerParam:(id)param forKey:(BDSSynthesizerParamKey)key __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSError*)setSynthParam:(id)param forKey:(BDSSynthesizerParamKey)key"))); 278 | 279 | /* 280 | * @brief get current value of parameter 281 | * @param key Key for parameter. 282 | * @param err If not nil, is set to BDS_SYNTHESIZER_PARAM_ERR_OK on success or error code on failure. 283 | * @return parameter object or nil. Refer to enum BDSSynthesizerParamKey for object types for different keys. 284 | */ 285 | -(id)getSynthesizerParamforKey:(BDSSynthesizerParamKey)key error:(BDSSynthesizerParamError*)err __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(id)getSynthParamforKey:(BDSSynthesizerParamKey)key withError:(NSError**)err"))); 286 | 287 | /** 288 | * -(BDSSynthesizerParamError)setCallbackQueue:(dispatch_queue_t)callbackQueue; 289 | * @brief YOU CAN IGNORE THIS IF YOU ARE GOING TO USE THIS SDK DIRECTLY FROM UI THREAD. 290 | * Sets the queue that should be used for making callbacks to BDSSpeechSynthesizerDelegate. 291 | * By default UI queue is used. 292 | * 293 | * @param callbackQueue A serial queue for making callbacks. (Using concurrent queue may result in 294 | * unexpected behaviour in some cases) 295 | * 296 | * @sample [[BDSSpeechSynthesizer sharedInstance] setCallbackQueue:dispatch_queue_create("MY_CALLBACK", DISPATCH_QUEUE_SERIAL)]; 297 | * 298 | * @return BDS_SYNTHESIZER_PARAM_ERR_OK On success. 299 | * BDS_SYNTHESIZER_PARAM_ERR_SDK_BUSY If synthesis is running. 300 | * BDS_SYNTHESIZER_PARAM_ERR_SDK_UNINIT If SDK is not properly initialized. 301 | * 302 | */ 303 | -(BDSSynthesizerParamError)setCallbackQueue:(dispatch_queue_t)callbackQueue __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSError*)setSDKCallbackQueue:(dispatch_queue_t)callbackQueue"))); 304 | 305 | /** 306 | * @brief 启动合成引擎 307 | * 308 | * @param textDatFilePath 文本分析数据文件路径 309 | * @param speechDataPath 声学模型数据文件路径 310 | * @param licenseFilePath 授权文件路径,如果没有本地授权可传入nil 311 | * @param appCode 用户持有的授权app code 312 | * 313 | * @return 错误码 314 | */ 315 | - (BDSErrEngine)startTTSEngine: (NSString*)textDatFilePath 316 | speechDataPath: (NSString*)speechDatFilePath 317 | licenseFilePath: (NSString*)licenseFilePath 318 | withAppCode: (NSString*)appCode __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)loadOfflineEngine:speechDataPath:licenseFilePath:withAppCode:"))); 319 | 320 | -(BDSErrEngine)loadEnglishData: (NSString*)textDataPath 321 | speechData: (NSString*)speechDataPath __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)loadEnglishDataForOfflineEngine:speechData:"))); 322 | 323 | 324 | /** 325 | * @brief 重新加载文本分析数据文件或者声学模型数据文件 326 | * 327 | * @param datFilePath: 数据文件路径 328 | * 329 | * @return 错误码 330 | */ 331 | - (BDSErrEngine)reinitTTSData: (NSString*)datFilePath __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)reinitOfflineEngineData:(NSString*)datFilePath"))); 332 | 333 | /** 334 | * @brief 加载定制库,在startTTSEngine:licenseFilePath:withAppCode:消息被调用后,调用此函数 335 | * 336 | * @param datFilePath 定制库路径 337 | * 338 | * @return 错误码 339 | */ 340 | - (BDSErrEngine)loadDomainData:(NSString*)datFilePath __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)loadDomainDataForOfflineEngine:(NSString*)datFilePath"))); 341 | 342 | /** 343 | * @brief 卸载定制库 344 | * 345 | * @return 错误码 346 | */ 347 | - (BDSErrEngine)unloadDomainData __attribute__((deprecated("This interface has been scheduled for removal in near future. Use - (NSError*)unloadDomainDataFromOfflineEngine"))); 348 | 349 | /** 350 | * @brief 开始文本合成但不朗读,开发者需要通过BDSSpeechSynthesizerDelegate的 351 | * synthesizerNewDataArrived:data:isLastData:sentenceNumber:方法传回的数据自行播放 352 | * The sentence number passed to callbacks will be 0 353 | * 354 | * @param text 需要语音合成的文本 355 | */ 356 | - (BDSStartSynthesisError)synthesize:(NSString *)text __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err"))); 357 | 358 | /** 359 | * @brief 开始文本合成但不朗读,开发者需要通过BDSSpeechSynthesizerDelegate的 360 | * synthesizerNewDataArrived:data:isLastData:sentenceNumber:方法传回的数据自行播放 361 | * 362 | * @param strings 需要语音合成的文本 363 | * The sentence number passed to callbacks indicates the index of string in this array. 364 | */ 365 | -(BDSStartSynthesisError)batchSynthesize:(NSArray *)strings __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err"))); 366 | 367 | /** 368 | * @brief 开始文本合成并朗读 369 | * The sentence number passed to callbacks will be 0 370 | * 371 | * @param text 需要朗读的文本 372 | */ 373 | - (BDSStartSynthesisError)speak:(NSString *)text __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) speakSentence:(NSString*)sentence withError:(NSError**)err"))); 374 | 375 | /** 376 | * @brief 开始文本合成并朗读 377 | * 378 | * @param strings 需要朗读的文本 379 | * The sentence number passed to callbacks indicates the index of string in this array. 380 | */ 381 | - (BDSStartSynthesisError)batchSpeak:(NSArray*)strings __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) speakSentence:(NSString*)sentence withError:(NSError**)err"))); 382 | 383 | /** 384 | * @brief Start new speak task with sentences or add more sentences to current playback 385 | * 386 | * @param sentences Array of sentences to be added. 387 | * @param generatedIDs Empty mutable array, on return contains array of NSNumber objects indicating 388 | * IDs for passed sentences. If passed array is not empty, generated IDs will be 389 | * added to the end of the array. 390 | * The returned IDs corresbond to the SynthesizeSentence- and SpeakSentence- 391 | * parameters passed to BDSSpeechSynthesizerDelegate's callback methods. 392 | * 393 | * @note The ID is a running number which is initially 0 and increases by one for each sentence 394 | * passed here. The number gets reset to 0 when old synthesize-, batchSynthesize-, speak- 395 | * and batchSpeak-interfaces are used. This is to maintain backward compatibility of the SDK. 396 | * 397 | * @return Error code. If != BDS_START_SYNTHESIS_OK, no sentences have been added and generatedIDs is unchanged. 398 | */ 399 | - (BDSStartSynthesisError)queueSpeakSentences:(NSArray*)sentences sentenceIDs:(NSMutableArray*)generatedIDs __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) speakSentence:(NSString*)sentence withError:(NSError**)err"))); 400 | 401 | /** 402 | * @brief Start new synthesis task with sentences or add more sentences to current synthesis 403 | * 404 | * @param sentences Array of sentences to be added. 405 | * @param generatedIDs Empty mutable array, on return contains array of NSNumber objects indicating 406 | * IDs for passed sentences. If passed array is not empty, generated IDs will be 407 | * added to the end of the array. 408 | * The returned IDs corresbond to the SynthesizeSentence- and SpeakSentence- 409 | * parameters passed to BDSSpeechSynthesizerDelegate's callback methods. 410 | * 411 | * @note The ID is a running number which is initially 0 and increases by one for each sentence 412 | * passed here. The number gets reset to 0 when old synthesize-, batchSynthesize-, speak- 413 | * and batchSpeak-interfaces are used. This is to maintain backward compatibility of the SDK. 414 | * 415 | * @return Error code. If != BDS_START_SYNTHESIS_OK, no sentences have been added and generatedIDs is unchanged. 416 | */ 417 | - (BDSStartSynthesisError)queueSynthesizeSentences:(NSArray*)sentences sentenceIDs:(NSMutableArray*)generatedIDs __attribute__((deprecated("This interface has been scheduled for removal in near future. Use -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err"))); 418 | 419 | /** 420 | * @brief 获取错误码对应的描述 421 | * 422 | * @param errorCode 错误码 423 | * 424 | * @return 错误描述信息 425 | */ 426 | - (NSString *)errorDescriptionForCode:(NSInteger)errorCode __attribute__((deprecated("This interface has been scheduled for removal in near future. All new interfaces will begin returning NSError objects that already contain description"))); 427 | 428 | @end -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSpeechSynthesizerDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSSpeechSynthesizerDelegate.h 3 | // BDSSpeechSynthesizer 4 | // 5 | // Created by 段弘 on 13-11-23. 6 | // Copyright (c) 2013年 百度. All rights reserved. 7 | // 8 | 9 | #import 10 | @class BDSSpeechSynthesizer; 11 | 12 | typedef enum BDSAudioPlayerPauseSources 13 | { 14 | BDS_AUDIO_PLAYER_PAUSE_SOURCE_USER, 15 | BDS_AUDIO_PLAYER_PAUSE_SOURCE_AUDIO_INTERRUPT, 16 | BDS_AUDIO_PLAYER_PAUSE_SOURCE_ENTERED_BACKGROUND 17 | }BDSAudioPlayerPauseSources __attribute__((deprecated("This parameter will be removed from paused callback. Current implementation of synthesizerPaused is kept in for backward compatibility for now, but will always pass BDS_AUDIO_PLAYER_PAUSE_SOURCE_USER as source. Start using - (void)synthesizerdidPause; instead."))); 18 | 19 | 20 | typedef enum BDSAudioFormat{ 21 | BDS_AUDIO_FORMAT_PCM_8K = 0, 22 | BDS_AUDIO_FORMAT_PCM_16K = 1, 23 | BDS_AUDIO_FORMAT_MP3 = 2 24 | }BDSAudioFormat; 25 | 26 | @protocol BDSSpeechSynthesizerDelegate 27 | 28 | /** 29 | * @brief 合成器开始工作 30 | * 31 | * @param speechSynthesizer 合成器对象 32 | */ 33 | @optional 34 | /** 35 | * @brief Began synthesizing new sentence. 36 | * Will receive one call for each queued sentence when SDK starts synthesizing them 37 | * 38 | * @param SynthesizeSentence Sentence ID generated BY SDK and returned by 39 | * speakSentence- and synthesizeSentence- interface. 40 | * 41 | * SynthesizeSentence may be any value from NSInteger's value 42 | * range, including negative values but excluding -1, which is reserved to 43 | * indicate none/error. 44 | */ 45 | - (void)synthesizerStartWorkingSentence:(NSInteger)SynthesizeSentence; 46 | 47 | /** 48 | * @brief Finished synthesizing a sentence. 49 | * Will receive one call for each queued sentence when SDK finishes synthesizing them 50 | * 51 | * @param SynthesizeSentence Sentence ID generated BY SDK and returned by 52 | * speakSentence- and synthesizeSentence- interface. 53 | * 54 | * SynthesizeSentence may be any value from NSInteger's value 55 | * range, including negative values but excluding -1, which is reserved to 56 | * indicate none/error. 57 | */ 58 | - (void)synthesizerFinishWorkingSentence:(NSInteger)SynthesizeSentence; 59 | 60 | /** 61 | * @brief Began speak a sentence. 62 | * Will receive one call for each queued sentence when SDK begans playback on them 63 | * Not called if only synthesizing 64 | * 65 | * @param SpeakSentence Sentence ID generated BY SDK and returned by 66 | * speakSentence- interface. 67 | * 68 | * SpeakSentence may be any value from NSInteger's value 69 | * range, including negative values but excluding -1, which is reserved to 70 | * indicate none/error. 71 | */ 72 | - (void)synthesizerSpeechStartSentence:(NSInteger)SpeakSentence; 73 | /** 74 | * @brief 朗读完成 75 | * Will receive one call for each queued sentence when SDK finishes playback on them 76 | * Not called if only synthesizing 77 | * 78 | * @param SpeakSentence Sentence ID generated BY SDK and returned by 79 | * speakSentence- interface. 80 | * 81 | * SpeakSentence may be any value from NSInteger's value 82 | * range, including negative values but excluding -1, which is reserved to 83 | * indicate none/error. 84 | */ 85 | - (void)synthesizerSpeechEndSentence:(NSInteger)SpeakSentence; 86 | 87 | /** 88 | * @brief 新的语音数据已经合成 89 | * 90 | * @param newData 语音数据 91 | * @param fmt Audio format in passed buffer. 92 | * @param newLength Currently synthesized character count of current sentence. 93 | * 94 | * @param SynthesizeSentence Sentence ID generated BY SDK and returned by 95 | * speakSentence- and synthesizeSentence- interface. 96 | * 97 | * SynthesizeSentence may be any value from NSInteger's value 98 | * range, including negative values but excluding -1, which is reserved to 99 | * indicate none/error. 100 | */ 101 | - (void)synthesizerNewDataArrived:(NSData *)newData 102 | DataFormat:(BDSAudioFormat)fmt 103 | characterCount:(int)newLength 104 | sentenceNumber:(NSInteger)SynthesizeSentence; 105 | 106 | 107 | /** 108 | * @brief Gives an estimation about how many characters have been spoken so far. 109 | * Not called if only synthesizing 110 | * 111 | * @param length Currently finished speaking character count of current sentence. 112 | * 113 | * @param SpeakSentence Sentence ID generated BY SDK and returned by 114 | * speakSentence- interface. 115 | * 116 | * SpeakSentence may be any value from NSInteger's value 117 | * range, including negative values but excluding -1, which is reserved to 118 | * indicate none/error. 119 | */ 120 | - (void)synthesizerTextSpeakLengthChanged:(int)newLength 121 | sentenceNumber:(NSInteger)SpeakSentence; 122 | 123 | /** 124 | * @brief invoked when player gets paused 125 | */ 126 | - (void)synthesizerdidPause; 127 | 128 | - (void)synthesizerPaused:(BDSAudioPlayerPauseSources)src __attribute__((deprecated("src parameter will be removed from paused callback. Current implementation of synthesizerPaused is kept in for backward compatibility for now, but will always pass BDS_AUDIO_PLAYER_PAUSE_SOURCE_USER as pause source. Start using - (void)synthesizerdidPause; instead."))); 129 | 130 | /** 131 | * @brief invoked when player is resumed from pause 132 | */ 133 | - (void)synthesizerResumed; 134 | 135 | /** 136 | * @brief 合成器发生错误 137 | * 138 | * @param error 错误对象 139 | * @param SpeakSentence Sentence ID generated BY SDK and returned by 140 | * speakSentence- interface. 141 | * 142 | * @param SynthesizeSentence Sentence ID generated BY SDK and returned by 143 | * speakSentence- and synthesizeSentence- interface. 144 | * 145 | * SpeakSentence may be any value from NSInteger's value 146 | * range, including negative values, also -1 may be encountered in this callback 147 | * if error happened while only synthesizing or playback haven't started yet. 148 | * 149 | * SynthesizeSentence may be any value from NSInteger's value 150 | * range, including negative values, also -1 may be encountered in this callback 151 | * if error happened in player and synthesizer had already finished it's work. 152 | */ 153 | - (void)synthesizerErrorOccurred:(NSError *)error 154 | speaking:(NSInteger)SpeakSentence 155 | synthesizing:(NSInteger)SynthesizeSentence; 156 | 157 | @end -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSpeechSynthesizerErrors.h: -------------------------------------------------------------------------------- 1 | #ifndef BDSSpeechSynthesizer_BDSSpeechSynthesizerErrors_h 2 | #define BDSSpeechSynthesizer_BDSSpeechSynthesizerErrors_h 3 | 4 | #import 5 | 6 | 7 | #pragma mark - Error domains 8 | 9 | FOUNDATION_EXPORT NSString * const BDTTS_ERROR_DOMAIN_TTS; /* Synthesis issues */ 10 | FOUNDATION_EXPORT NSString * const BDTTS_ERROR_DOMAIN_AUTH; /* Client authentication issues */ 11 | FOUNDATION_EXPORT NSString * const BDTTS_ERROR_DOMAIN_NET; /* Network issues */ 12 | FOUNDATION_EXPORT NSString * const BDTTS_ERROR_DOMAIN_SERVER; /* Online TTS service returned issues */ 13 | FOUNDATION_EXPORT NSString * const BDTTS_ERROR_DOMAIN_EMBEDDED_TTS; /* Offline TTS issues */ 14 | FOUNDATION_EXPORT NSString * const BDTTS_ERROR_DOMAIN_INTERNAL; /* SDK Internal problems */ 15 | 16 | #pragma mark - Error codes 17 | 18 | /* 19 | * Error code definitions for most common issues, all errors returned as NSError objects. 20 | * Check the NSError's localized description to get error details. 21 | */ 22 | typedef enum BDTTSError 23 | { 24 | OK = 0, 25 | // BDTTS_ERROR_DOMAIN_TTS 26 | ERR_TEXT_TOO_SHORT = ((200 << 16)|(0x0000FFFF&-1)), 27 | ERR_TEXT_TOO_LONG = ((200 << 16)|(0x0000FFFF&-2)), 28 | ERR_ENGINE_BUSY = ((200 << 16)|(0x0000FFFF&-3)), 29 | ERR_INVALID_PARAM = ((200 << 16)|(0x0000FFFF&-8000)), 30 | ERR_SDK_UNINIT = ((200 << 16)|(0x0000FFFF&-8001)), 31 | 32 | // BDTTS_ERROR_DOMAIN_AUTH 33 | ERR_ONLINE_TTS_AUTH_CREDENTIALS_NOT_SET = ((200 << 16)|(0x0000FFFF&-6)), 34 | ERR_ONLINE_TTS_FAILED_GET_ACCESS_TOKEN = ((222 << 16)|(0x0000FFFF&-1)), 35 | ERR_OFFLINE_TTS_FAILED_GET_LICENSE = ((212 << 16)|(0x0000FFFF&-1)), 36 | ERR_OFFLINE_TTS_LICENSE_EXPIRED = ((212 << 16)|(0x0000FFFF&-10)), 37 | 38 | // BDTTS_ERROR_DOMAIN_NET 39 | ERR_NO_INTERNET = ((200 << 16)|(0x0000FFFF&-4)), 40 | ERR_DNS_FAILED = ((223 << 16)|(0x0000FFFF&-1)), 41 | ERR_ONLINE_TTS_REQUEST = ((223 << 16)|(0x0000FFFF&-2)), 42 | ERR_ONLINE_TTS_RESPONSE = ((223 << 16)|(0x0000FFFF&-3)), 43 | 44 | // BDTTS_ERROR_DOMAIN_EMBEDDED_TTS 45 | ERR_OFFLINE_ENGINE_LOAD_FAILED = ((210 << 16)|(0x0000FFFF&-1)), 46 | ERR_OFFLINE_ENGINE_NOT_LOADED = ((210 << 16)|(0x0000FFFF&-2)), 47 | ERR_OFFLINE_ENGINE_MISSING_PARAM = ((210 << 16)|(0x0000FFFF&-3)), 48 | ERR_OFFLINE_SYNTHESIS_FAILED = ((210 << 16)|(0x0000FFFF&-4)), 49 | ERR_OFFLINE_DATA_FILE_NOT_EXIST = ((210 << 16)|(0x0000FFFF&-8000)), 50 | ERR_OFFLINE_DATA_FILE_VERIFY_FAIL = ((210 << 16)|(0x0000FFFF&-8001)), 51 | ERR_OFFLINE_PARAM = ((210 << 16)|(0x0000FFFF&-8002)), 52 | ERR_OFFLINE_DATA_FILE_DETAIL_NOT_FOUND = ((210 << 16)|(0x0000FFFF&-8003)), 53 | }BDTTSError; 54 | 55 | #pragma mark - Synthesizer states 56 | 57 | typedef enum BDSSynthesizerStatus { 58 | /* 59 | * Failed to initialize SDK 60 | */ 61 | BDS_SYNTHESIZER_STATUS_NONE = 0, 62 | 63 | /* 64 | * SDK ready for use 65 | */ 66 | BDS_SYNTHESIZER_STATUS_IDLE, 67 | 68 | /* 69 | * SDK is synthesizing/speaking 70 | */ 71 | BDS_SYNTHESIZER_STATUS_WORKING, 72 | 73 | /* 74 | * Synthesis (and speech) is paused 75 | */ 76 | BDS_SYNTHESIZER_STATUS_PAUSED, 77 | 78 | /* 79 | * SDK has encountered error during previous synthesis. 80 | * SDK is ready for start new synthesis 81 | */ 82 | BDS_SYNTHESIZER_STATUS_ERROR, 83 | 84 | /* 85 | * SDK was cancelled by user during previous synthesis. 86 | * SDK is ready for start new synthesis 87 | */ 88 | BDS_SYNTHESIZER_STATUS_CANCELLED 89 | }BDSSynthesizerStatus; 90 | 91 | 92 | #pragma mark - Definitions for deprecated legacy interfaces 93 | 94 | typedef enum BDSStartSynthesisError 95 | { 96 | // Shared errors 97 | BDS_START_SYNTHESIS_OK = 0, /* No errors */ 98 | BDS_START_SYNTHESIS_SYNTHESIZER_UNINITIALIZED, /* Engine is not initialized */ 99 | BDS_START_SYNTHESIS_TEXT_EMPTY, /* Synthesis text is empty */ 100 | BDS_START_SYNTHESIS_TEXT_TOO_LONG, /* Synthesis text is too long */ 101 | BDS_START_SYNTHESIS_ENGINE_BUSY, /* Already synthesising, cancel first or wait */ 102 | BDS_START_SYNTHESIS_MALLOC_ERROR, /* failed to allocate resources */ 103 | BDS_START_SYNTHESIS_NO_NETWORK, /* No internet connectivity */ 104 | BDS_START_SYNTHESIS_NO_VERIFY_INFO, /* No product id or api keys set */ 105 | /* Offline TTS engine wasn't loaded */ 106 | BDS_START_SYNTHESIS_OFFLINE_ENGINE_NOT_LOADED, 107 | BDS_START_SYNTHESIS_ERROR_UNKNOWN /* Error code is unknown to legacy interface, must use new interfaces */ 108 | }BDSStartSynthesisError __attribute__((deprecated("This interface has been deprecated, all new interfaces work with NSError to report errors."))); 109 | 110 | typedef enum BDSSynthesisError 111 | { 112 | /* General usage */ 113 | BDS_UNKNOWN_ERROR = 30001, /* Unhandled error, see error description for details */ 114 | /* Playback errors */ 115 | BDS_PLAYER_FAILED_GET_STREAM_PROPERTIES = 25001, 116 | BDS_PLAYER_FAILED_OPEN_DEVICE, 117 | BDS_PLAYER_FAILED_OPEN_STREAM, 118 | BDS_PLAYER_ALLOC_FAIL, 119 | BDS_PLAYER_BAD_STREAM, 120 | BDS_PLAYER_START_PLAYBACK_FAILED, 121 | // Online TTS Errors 122 | /* Online TTS errors */ 123 | BDS_ONLINE_TTS_CONNECT_ERROR = 2001, 124 | BDS_ONLINE_TTS_RESPONSE_PARSE_ERROR = 2002, 125 | BDS_ONLINE_TTS_PARAM_ERROR = 4501, 126 | /** 文本编码不支持 */ 127 | BDS_ONLINE_TTS_TEXT_ENCODE_NOT_SUPPORTED = 4502, 128 | /** 认证错误 */ 129 | BDS_ONLINE_TTS_VERIFY_ERROR = 4503, 130 | /** 获取access token失败 */ 131 | BDS_ONLINE_TTS_GET_ACCESS_TOKEN_FAILED = 4001, 132 | 133 | // Oflfine TTS errors 134 | BDS_ETTS_ERR_PARTIAL_SYNTH = 10001, 135 | BDS_ETTS_ERR_CONFIG, 136 | BDS_ETTS_ERR_RESOURCE, 137 | BDS_ETTS_ERR_HANDLE, 138 | BDS_ETTS_ERR_PARMAM, 139 | BDS_ETTS_ERR_MEMORY, 140 | BDS_ETTS_ERR_TOO_MANY_TEXT, 141 | BDS_ETTS_ERR_RUN_TIME, 142 | BDS_ETTS_ERR_NO_TEXT, 143 | BDS_ETTS_ERR_LICENSE, 144 | 145 | }BDSSynthesisError __attribute__((deprecated("This interface has been deprecated, all new interfaces work with NSError to report errors."))); 146 | 147 | typedef enum BDSErrEngine{ 148 | BDS_ERR_ENGINE_OK = 0, 149 | BDS_ERR_ENGINE_PARTIAL_SYNTH = 10001, 150 | BDS_ERR_ENGINE_CONFIG, 151 | BDS_ERR_ENGINE_RESOURCE, 152 | BDS_ERR_ENGINE_HANDLE, 153 | BDS_ERR_ENGINE_PARMAM, 154 | BDS_ERR_ENGINE_MEMORY, 155 | BDS_ERR_ENGINE_MANY_TEXT, 156 | BDS_ERR_ENGINE_RUN_TIME, 157 | BDS_ERR_ENGINE_NO_TEXT, 158 | BDS_ERR_ENGINE_LICENSE, 159 | BDS_ERR_ENGINE_MALLOC, 160 | BDS_ERR_ENGINE_ENGINE_NOT_INIT, 161 | BDS_ERR_ENGINE_SESSION_NOT_INIT, 162 | BDS_ERR_ENGINE_GET_LICENSE, 163 | BDS_ERR_ENGINE_LICENSE_EXPIRED, 164 | BDS_ERR_ENGINE_VERIFY_LICENSE, 165 | BDS_ERR_ENGINE_INVALID_PARAM, 166 | BDS_ERR_ENGINE_DATA_FILE_NOT_EXIST, 167 | BDS_ERR_ENGINE_VERIFY_DATA_FILE, 168 | BDS_ERR_ENGINE_GET_DATA_FILE_PARAM, 169 | BDS_ERR_ENGINE_ENCODE_TEXT, 170 | BDS_ERR_ENGINE_INIT_FAIL, 171 | BDS_ERR_ENGINE_IN_USE, 172 | BDS_ERR_ENGINE_BAD_INIT_STATE, 173 | BDS_ERR_ENGINE_UNKNOWN_ERROR 174 | }BDSErrEngine __attribute__((deprecated("This interface has been deprecated, all new interfaces work with NSError to report errors."))); 175 | #endif 176 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSpeechSynthesizerParams.h: -------------------------------------------------------------------------------- 1 | // 2 | // BDSSpeechSynthesizerParams.h 3 | // BDSSpeechSynthesizer 4 | // 5 | // Created by lappi on 7/31/15. 6 | // Copyright (c) 2015 百度. All rights reserved. 7 | // 8 | 9 | #ifndef BDSSpeechSynthesizer_BDSSpeechSynthesizerParams_h 10 | #define BDSSpeechSynthesizer_BDSSpeechSynthesizerParams_h 11 | 12 | #pragma mark - param definitions 13 | 14 | typedef enum BDSSynthesizerParamKey 15 | { 16 | BDS_SYNTHESIZER_PARAM_SPEED = 0, /* NSNumber([0...9]) */ 17 | BDS_SYNTHESIZER_PARAM_PITCH, /* NSNumber([0...9]) */ 18 | BDS_SYNTHESIZER_PARAM_VOLUME, /* NSNumber([0...9]) */ 19 | /* 20 | * BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT 21 | * If enabled (default) SDK will manage AVAudioSession internally: 22 | * - Activate session when it's needed, disable when no longer needed. 23 | * - Handle audio session interruptions. 24 | * - Manage audio session category. 25 | */ 26 | BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT, /* NSNumber(BOOL), default YES*/ 27 | 28 | /* 29 | * You may use this to adjust the withOptions parameter SDK passes to AVAudioSession when it calls 30 | * [[AVAudioSession sharedInstance] setCategory:withOptions:error:]; 31 | * Effective only when BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT is set to YES 32 | */ 33 | BDS_SYNTHESIZER_PARAM_AUDIO_SESSION_CATEGORY_OPTIONS, /* NSNumber(AVAudioSessionCategoryOptions), 34 | default (AVAudioSessionCategoryOptionMixWithOthers| 35 | AVAudioSessionCategoryOptionDuckOthers) 36 | */ 37 | BDS_SYNTHESIZER_PARAM_PID, /* NSNumber(PID number) */ 38 | #pragma mark - deprecated 39 | BDS_SYNTHESIZER_PARAM_LANGUAGE, /* NSNumber(enum BDSSynthesizerLanguages) */ 40 | BDS_SYNTHESIZER_PARAM_TEXT_ENCODE, /* NSNumber(enum BDSSynthesizerTextEncodings) */ 41 | #pragma mark - end deprecated 42 | BDS_SYNTHESIZER_PARAM_AUDIO_ENCODING, /* NSNumber(enum BDSSynthesizerAudioEncoding) */ 43 | BDS_SYNTHESIZER_PARAM_SPEAKER, /* NSNumber(enum BDSSynthesizerSpeaker) */ 44 | BDS_SYNTHESIZER_PARAM_USER_AGENT, /* NSString */ 45 | 46 | /* 如果与百度语音技术部有直接合作关系,才需要考虑此方法,否则请勿随意设置服务器地址 */ 47 | /* tts合成服务器地址 NSString */ 48 | BDS_SYNTHESIZER_PARAM_SERVER_URL, 49 | 50 | /* 51 | * 设置tts超时时间 NSNumber([timeout in seconds, float]) must be at least 0.8 52 | * any smaller values will be set to 0.8 53 | * 54 | * Effective only when synthesizing without speak using following interface: 55 | * -(NSInteger) synthesizeSentence:(NSString*)sentence withError:(NSError**)err 56 | * 57 | * If using following speak interface, this value is ignored and timeout is determined internally by SDK. 58 | * -(NSInteger) speakSentence:( NSString* _Nonnull )sentence withError:(NSError**)err 59 | */ 60 | 61 | BDS_SYNTHESIZER_PARAM_ONLINE_REQUEST_TIMEOUT, 62 | 63 | BDS_SYNTHESIZER_PARAM_ETTS_OPEN_XML, /* NSNumber([0,1]) */ 64 | BDS_SYNTHESIZER_PARAM_ETTS_DOMAIN_SYNTH, /* NSNumber([0,1]) */ 65 | BDS_SYNTHESIZER_PARAM_ETTS_AUDIO_FORMAT, /* NSNumber(enum ETTS_AUDIO_TYPE) */ 66 | BDS_SYNTHESIZER_PARAM_ETTS_VOCODER_OPTIM_LEVEL, /* NSNumber(enum ETTS_VOCODER_OPTIM_LEVEL) */ 67 | BDS_SYNTHESIZER_PARAM_ONLINE_TTS_THRESHOLD, /* NSNumber(enum ONLINE_TTS_TRESSHOLD) */ 68 | /* 69 | * BDS_SYNTHESIZER_PARAM_ENABLE_TIMEOUT_OPTIMIZATION 70 | * If this is enabled, strategy is set to TTS_MODE_ONLINE_PRI, offline engine is 71 | * succesfully loaded and you are using speakSentence interface to synthesise and play, 72 | * SDK will set a shorter timeout (about 1.5 seconds) for first request of first sentence 73 | * to make sure the playback begins in a reasonable time even in bad networks. 74 | * 75 | * Disabled by default. 76 | */ 77 | BDS_SYNTHESIZER_PARAM_ENABLE_TIMEOUT_OPTIMIZATION, /* NSNumber([0,1]) */ 78 | BDS_SYNTHESIZER_PARAM_SYNTH_STRATEGY, /* NSNumber(enum TTS_MODE) */ 79 | }BDSSynthesizerParamKey; 80 | 81 | /* PARAM VALUES */ 82 | 83 | /* Use with BDS_SYNTHESIZER_PARAM_AUDIO_ENCODING */ 84 | enum BDSSynthesizerAudioEncoding 85 | { 86 | BDS_SYNTHESIZER_AUDIO_ENCODE_BV_16K = 0, /** bv 16k比特率 */ 87 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_6K6, /** amr 6.6k比特率 */ 88 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_8K85, /** amr 8.85k比特率 */ 89 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_12K65, /** amr 12.65k比特率 */ 90 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_14K25, /** amr 14.25k比特率 */ 91 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_15K85, /** amr 15.85k比特率 */ 92 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_18K25, /** amr 18.25k比特率 */ 93 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_19K85, /** amr 19.85k比特率 */ 94 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_23K05, /** amr 23.05k比特率 */ 95 | BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_23K85, /** amr 23.85k比特率 */ 96 | BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_8K, /** opus 8k比特率 */ 97 | BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_16K, /** opus 16k比特率 */ 98 | BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_18K, /** opus 18k比特率 */ 99 | BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_20K, /** opus 20k比特率 */ 100 | BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_24K, /** opus 24k比特率 */ 101 | BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_32K, /** opus 32k比特率 */ 102 | BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_8K, /** mp3 8k比特率 */ 103 | BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_11K, /** mp3 11k比特率 */ 104 | BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_16K, /** mp3 16k比特率 */ 105 | BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_24K, /** mp3 24k比特率 */ 106 | BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_32K, /** mp3 32k比特率 */ 107 | }; 108 | /* Use with BDS_SYNTHESIZER_PARAM_SPEAKER */ 109 | enum BDSSynthesizerSpeaker 110 | { 111 | BDS_SYNTHESIZER_SPEAKER_FEMALE = 0, /* 女声 (f7) */ 112 | BDS_SYNTHESIZER_SPEAKER_MALE = 1, /* 男声 (macs) */ 113 | BDS_SYNTHESIZER_SPEAKER_MALE_2 = 2, /* 男声 (m15) */ 114 | BDS_SYNTHESIZER_SPEAKER_MALE_3 = 3 /* 男声 (yyjw) */ 115 | }; 116 | 117 | // 输出的pcm音频数据类型: 16K(默认)/ 8K 118 | // Use with BDS_SYNTHESIZER_PARAM_ETTS_AUDIO_FORMAT 119 | typedef enum ETTS_AUDIO_TYPE 120 | { 121 | ETTS_AUDIO_TYPE_PCM_16K, // 默认 122 | ETTS_AUDIO_TYPE_PCM_8K 123 | }ETTS_AUDIO_TYPE; 124 | 125 | // VOCODER优化等级:// 0级表示没有优化,音质效果最好,数值越大速度越快,但音质效果会降低 126 | // Use with BDS_SYNTHESIZER_PARAM_ETTS_VOCODER_OPTIM_LEVEL 127 | enum ETTS_VOCODER_OPTIM_LEVEL 128 | { 129 | ETTS_VOCODER_OPTIM_LEVEL_0, 130 | ETTS_VOCODER_OPTIM_LEVEL_1, 131 | ETTS_VOCODER_OPTIM_LEVEL_2, 132 | }; 133 | 134 | /* Use with BDS_SYNTHESIZER_PARAM_SYNTH_STRATEGY */ 135 | typedef enum TTS_MODE 136 | { 137 | TTS_MODE_ONLINE, 138 | TTS_MODE_OFFLINE, 139 | TTS_MODE_ONLINE_PRI, 140 | TTS_MODE_OFFLINE_PRI, 141 | }TTS_MODE; 142 | 143 | typedef enum ONLINE_TTS_TRESHOLD 144 | { 145 | /* Use online TTS when there is internet connectivity (Default) */ 146 | REQ_CONNECTIVITY_ANY = 0, 147 | /* Use online TTS when have at least 3G Connectivity */ 148 | REQ_CONNECTIVITY_3G, 149 | /* Use online TTS when have at least 4G Connectivity */ 150 | REQ_CONNECTIVITY_4G, 151 | /* Use online TTS only when connected to wifi */ 152 | REQ_CONNECTIVITY_WIFI 153 | }ONLINE_TTS_TRESHOLD; 154 | 155 | // 音库文件相关参数 156 | typedef enum TTSDataParam{ 157 | TTS_DATA_PARAM_DATE, 158 | TTS_DATA_PARAM_SPEAKER, 159 | TTS_DATA_PARAM_GENDER, 160 | TTS_DATA_PARAM_CATEGORY, 161 | TTS_DATA_PARAM_LANGUAGE, 162 | TTS_DATA_PARAM_VERSION, 163 | TTS_DATA_PARAM_DOMAIN, 164 | TTS_DATA_PARAM_TYPE, 165 | TTS_DATA_PARAM_QUALITY 166 | }TTSDataParam; 167 | 168 | #pragma mark - deprecated legacy param definitions 169 | typedef enum BDSSynthesizerParamError 170 | { 171 | BDS_SYNTHESIZER_PARAM_ERR_OK = 0, 172 | BDS_SYNTHESIZER_PARAM_ERR_NOT_SUPPORT = 6000, 173 | BDS_SYNTHESIZER_PARAM_ERR_INVALID_VALUE, 174 | BDS_SYNTHESIZER_PARAM_ERR_SDK_UNINIT, 175 | BDS_SYNTHESIZER_PARAM_ERR_SDK_BUSY, 176 | BDS_SYNTHESIZER_PARAM_SET_FAILED, 177 | BDS_SYNTHESIZER_PARAM_ERR_UNKNOWN /* Error unknown to legacy interface, use new interfaces */ 178 | }BDSSynthesizerParamError __attribute__((deprecated("This interface has been deprecated, all new interfaces work with NSError to report errors."))); 179 | 180 | /* PARAM VALUES */ 181 | /* Use with BDS_SYNTHESIZER_PARAM_LANGUAGE */ 182 | enum BDSSynthesizerLanguages 183 | { 184 | BDS_SYNTHESIZER_LANGUAGE_ZH = 0, 185 | BDS_SYNTHESIZER_LANGUAGE_EN 186 | }; 187 | /* Use with BDS_SYNTHESIZER_PARAM_TEXT_ENCODE */ 188 | enum BDSSynthesizerTextEncodings 189 | { 190 | BDS_SYNTHESIZER_TEXT_ENCODE_UTF8 = 2 191 | }; 192 | 193 | #endif 194 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSynthesizerLogLevel.h: -------------------------------------------------------------------------------- 1 | // 2 | // SynthesizerLogLevel.h 3 | // BDSSpeechSynthesizer 4 | // 5 | // Created by lappi on 4/14/15. 6 | // Copyright (c) 2015 百度. All rights reserved. 7 | // 8 | 9 | #ifndef BDSSynthesizerLogLevel_h 10 | #define BDSSynthesizerLogLevel_h 11 | 12 | /** 13 | * @brief 日志级别枚举类型 14 | */ 15 | typedef enum BDSLogLevel { 16 | BDS_PUBLIC_LOG_OFF = 0, 17 | BDS_PUBLIC_LOG_ERROR = 1, 18 | BDS_PUBLIC_LOG_WARN = 2, 19 | BDS_PUBLIC_LOG_INFO = 3, 20 | BDS_PUBLIC_LOG_DEBUG = 4, 21 | BDS_PUBLIC_LOG_VERBOSE = 5, 22 | } BDSLogLevel; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ios/BaiduVoiceSDK/BDSClientLib/libBaiduSpeechSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/ios/BaiduVoiceSDK/BDSClientLib/libBaiduSpeechSDK.a -------------------------------------------------------------------------------- /ios/ReactNativeBaiduVoiceRecognition.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 35366A1C1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 35366A1B1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.h */; }; 11 | 35366A1E1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.m in Sources */ = {isa = PBXBuildFile; fileRef = 35366A1D1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.m */; }; 12 | 35366A301D2FA69B00DB398A /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35366A2F1D2FA69B00DB398A /* GLKit.framework */; }; 13 | 35366A321D2FA6A500DB398A /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35366A311D2FA6A500DB398A /* SystemConfiguration.framework */; }; 14 | 35366A341D2FA6AF00DB398A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35366A331D2FA6AF00DB398A /* AudioToolbox.framework */; }; 15 | 35366A361D2FA6BD00DB398A /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35366A351D2FA6BD00DB398A /* AVFoundation.framework */; }; 16 | 35366A381D2FA6C600DB398A /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35366A371D2FA6C600DB398A /* CFNetwork.framework */; }; 17 | 35366A3A1D2FA6D100DB398A /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35366A391D2FA6D100DB398A /* CoreLocation.framework */; }; 18 | 35366A3C1D2FA6DF00DB398A /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35366A3B1D2FA6DF00DB398A /* CoreTelephony.framework */; }; 19 | 35366A7B1D2FAF4300DB398A /* libBaiduSpeechSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 35366A7A1D2FAF4300DB398A /* libBaiduSpeechSDK.a */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXCopyFilesBuildPhase section */ 23 | 35366A161D2FA04200DB398A /* CopyFiles */ = { 24 | isa = PBXCopyFilesBuildPhase; 25 | buildActionMask = 2147483647; 26 | dstPath = "include/$(PRODUCT_NAME)"; 27 | dstSubfolderSpec = 16; 28 | files = ( 29 | 35366A1C1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.h in CopyFiles */, 30 | ); 31 | runOnlyForDeploymentPostprocessing = 0; 32 | }; 33 | /* End PBXCopyFilesBuildPhase section */ 34 | 35 | /* Begin PBXFileReference section */ 36 | 35366A181D2FA04200DB398A /* libReactNativeBaiduVoiceRecognition.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativeBaiduVoiceRecognition.a; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 35366A1B1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeBaiduVoiceRecognition.h; sourceTree = ""; }; 38 | 35366A1D1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReactNativeBaiduVoiceRecognition.m; sourceTree = ""; }; 39 | 35366A2F1D2FA69B00DB398A /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; }; 40 | 35366A311D2FA6A500DB398A /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 41 | 35366A331D2FA6AF00DB398A /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 42 | 35366A351D2FA6BD00DB398A /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 43 | 35366A371D2FA6C600DB398A /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; 44 | 35366A391D2FA6D100DB398A /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; 45 | 35366A3B1D2FA6DF00DB398A /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; 46 | 35366A641D2FAEC100DB398A /* BDSASRDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSASRDefines.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/BDSASRDefines.h; sourceTree = ""; }; 47 | 35366A651D2FAEC100DB398A /* BDSASRParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSASRParameters.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/BDSASRParameters.h; sourceTree = ""; }; 48 | 35366A661D2FAEC100DB398A /* BDSEventManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSEventManager.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/BDSEventManager.h; sourceTree = ""; }; 49 | 35366A671D2FAEC100DB398A /* BDSUploaderDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSUploaderDefines.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/BDSUploaderDefines.h; sourceTree = ""; }; 50 | 35366A681D2FAEC100DB398A /* BDSUploaderParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSUploaderParameters.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/BDSUploaderParameters.h; sourceTree = ""; }; 51 | 35366A691D2FAEC100DB398A /* BDSWakeupDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSWakeupDefines.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/BDSWakeupDefines.h; sourceTree = ""; }; 52 | 35366A6A1D2FAEC100DB398A /* BDSWakeupParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSWakeupParameters.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/BDSWakeupParameters.h; sourceTree = ""; }; 53 | 35366A6D1D2FAEF300DB398A /* BDRecognizerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDRecognizerViewController.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/UIHeaders/BDRecognizerViewController.h; sourceTree = ""; }; 54 | 35366A6E1D2FAEF300DB398A /* BDRecognizerViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDRecognizerViewDelegate.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/UIHeaders/BDRecognizerViewDelegate.h; sourceTree = ""; }; 55 | 35366A6F1D2FAEF300DB398A /* BDRecognizerViewParamsObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDRecognizerViewParamsObject.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/UIHeaders/BDRecognizerViewParamsObject.h; sourceTree = ""; }; 56 | 35366A701D2FAEF300DB398A /* BDTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDTheme.h; path = BaiduVoiceSDK/BDSClientHeaders/ASR/UIHeaders/BDTheme.h; sourceTree = ""; }; 57 | 35366A731D2FAF1C00DB398A /* BDSBuiltInPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSBuiltInPlayer.h; path = BaiduVoiceSDK/BDSClientHeaders/TTS/BDSBuiltInPlayer.h; sourceTree = ""; }; 58 | 35366A741D2FAF1C00DB398A /* BDSMixedModeSynthesizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSMixedModeSynthesizer.h; path = BaiduVoiceSDK/BDSClientHeaders/TTS/BDSMixedModeSynthesizer.h; sourceTree = ""; }; 59 | 35366A751D2FAF1C00DB398A /* BDSSpeechSynthesizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSSpeechSynthesizer.h; path = BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSpeechSynthesizer.h; sourceTree = ""; }; 60 | 35366A761D2FAF1C00DB398A /* BDSSpeechSynthesizerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSSpeechSynthesizerDelegate.h; path = BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSpeechSynthesizerDelegate.h; sourceTree = ""; }; 61 | 35366A771D2FAF1C00DB398A /* BDSSpeechSynthesizerErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSSpeechSynthesizerErrors.h; path = BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSpeechSynthesizerErrors.h; sourceTree = ""; }; 62 | 35366A781D2FAF1C00DB398A /* BDSSpeechSynthesizerParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSSpeechSynthesizerParams.h; path = BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSpeechSynthesizerParams.h; sourceTree = ""; }; 63 | 35366A791D2FAF1C00DB398A /* BDSSynthesizerLogLevel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BDSSynthesizerLogLevel.h; path = BaiduVoiceSDK/BDSClientHeaders/TTS/BDSSynthesizerLogLevel.h; sourceTree = ""; }; 64 | 35366A7A1D2FAF4300DB398A /* libBaiduSpeechSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libBaiduSpeechSDK.a; path = BaiduVoiceSDK/BDSClientLib/libBaiduSpeechSDK.a; sourceTree = ""; }; 65 | /* End PBXFileReference section */ 66 | 67 | /* Begin PBXFrameworksBuildPhase section */ 68 | 35366A151D2FA04200DB398A /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | 35366A7B1D2FAF4300DB398A /* libBaiduSpeechSDK.a in Frameworks */, 73 | 35366A3C1D2FA6DF00DB398A /* CoreTelephony.framework in Frameworks */, 74 | 35366A3A1D2FA6D100DB398A /* CoreLocation.framework in Frameworks */, 75 | 35366A381D2FA6C600DB398A /* CFNetwork.framework in Frameworks */, 76 | 35366A361D2FA6BD00DB398A /* AVFoundation.framework in Frameworks */, 77 | 35366A341D2FA6AF00DB398A /* AudioToolbox.framework in Frameworks */, 78 | 35366A321D2FA6A500DB398A /* SystemConfiguration.framework in Frameworks */, 79 | 35366A301D2FA69B00DB398A /* GLKit.framework in Frameworks */, 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | /* End PBXFrameworksBuildPhase section */ 84 | 85 | /* Begin PBXGroup section */ 86 | 35366A0F1D2FA04200DB398A = { 87 | isa = PBXGroup; 88 | children = ( 89 | 35366A6B1D2FAEC700DB398A /* BDSClientHeaders */, 90 | 35366A3D1D2FA6E900DB398A /* Frameworks */, 91 | 35366A1A1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognizition */, 92 | 35366A191D2FA04200DB398A /* Products */, 93 | ); 94 | sourceTree = ""; 95 | }; 96 | 35366A191D2FA04200DB398A /* Products */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 35366A181D2FA04200DB398A /* libReactNativeBaiduVoiceRecognition.a */, 100 | ); 101 | name = Products; 102 | sourceTree = ""; 103 | }; 104 | 35366A1A1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognizition */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 35366A1B1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.h */, 108 | 35366A1D1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.m */, 109 | ); 110 | path = ReactNativeBaiduVoiceRecognizition; 111 | sourceTree = ""; 112 | }; 113 | 35366A3D1D2FA6E900DB398A /* Frameworks */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 35366A7A1D2FAF4300DB398A /* libBaiduSpeechSDK.a */, 117 | 35366A3B1D2FA6DF00DB398A /* CoreTelephony.framework */, 118 | 35366A391D2FA6D100DB398A /* CoreLocation.framework */, 119 | 35366A371D2FA6C600DB398A /* CFNetwork.framework */, 120 | 35366A351D2FA6BD00DB398A /* AVFoundation.framework */, 121 | 35366A331D2FA6AF00DB398A /* AudioToolbox.framework */, 122 | 35366A311D2FA6A500DB398A /* SystemConfiguration.framework */, 123 | 35366A2F1D2FA69B00DB398A /* GLKit.framework */, 124 | ); 125 | name = Frameworks; 126 | sourceTree = ""; 127 | }; 128 | 35366A6B1D2FAEC700DB398A /* BDSClientHeaders */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | 35366A721D2FAF0B00DB398A /* TTS */, 132 | 35366A711D2FAEFB00DB398A /* ASR */, 133 | ); 134 | name = BDSClientHeaders; 135 | sourceTree = ""; 136 | }; 137 | 35366A6C1D2FAEE000DB398A /* UIHeaders */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | 35366A6D1D2FAEF300DB398A /* BDRecognizerViewController.h */, 141 | 35366A6E1D2FAEF300DB398A /* BDRecognizerViewDelegate.h */, 142 | 35366A6F1D2FAEF300DB398A /* BDRecognizerViewParamsObject.h */, 143 | 35366A701D2FAEF300DB398A /* BDTheme.h */, 144 | ); 145 | name = UIHeaders; 146 | sourceTree = ""; 147 | }; 148 | 35366A711D2FAEFB00DB398A /* ASR */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | 35366A6C1D2FAEE000DB398A /* UIHeaders */, 152 | 35366A641D2FAEC100DB398A /* BDSASRDefines.h */, 153 | 35366A651D2FAEC100DB398A /* BDSASRParameters.h */, 154 | 35366A661D2FAEC100DB398A /* BDSEventManager.h */, 155 | 35366A671D2FAEC100DB398A /* BDSUploaderDefines.h */, 156 | 35366A681D2FAEC100DB398A /* BDSUploaderParameters.h */, 157 | 35366A691D2FAEC100DB398A /* BDSWakeupDefines.h */, 158 | 35366A6A1D2FAEC100DB398A /* BDSWakeupParameters.h */, 159 | ); 160 | name = ASR; 161 | sourceTree = ""; 162 | }; 163 | 35366A721D2FAF0B00DB398A /* TTS */ = { 164 | isa = PBXGroup; 165 | children = ( 166 | 35366A731D2FAF1C00DB398A /* BDSBuiltInPlayer.h */, 167 | 35366A741D2FAF1C00DB398A /* BDSMixedModeSynthesizer.h */, 168 | 35366A751D2FAF1C00DB398A /* BDSSpeechSynthesizer.h */, 169 | 35366A761D2FAF1C00DB398A /* BDSSpeechSynthesizerDelegate.h */, 170 | 35366A771D2FAF1C00DB398A /* BDSSpeechSynthesizerErrors.h */, 171 | 35366A781D2FAF1C00DB398A /* BDSSpeechSynthesizerParams.h */, 172 | 35366A791D2FAF1C00DB398A /* BDSSynthesizerLogLevel.h */, 173 | ); 174 | name = TTS; 175 | sourceTree = ""; 176 | }; 177 | /* End PBXGroup section */ 178 | 179 | /* Begin PBXNativeTarget section */ 180 | 35366A171D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition */ = { 181 | isa = PBXNativeTarget; 182 | buildConfigurationList = 35366A211D2FA04200DB398A /* Build configuration list for PBXNativeTarget "ReactNativeBaiduVoiceRecognition" */; 183 | buildPhases = ( 184 | 35366A141D2FA04200DB398A /* Sources */, 185 | 35366A151D2FA04200DB398A /* Frameworks */, 186 | 35366A161D2FA04200DB398A /* CopyFiles */, 187 | ); 188 | buildRules = ( 189 | ); 190 | dependencies = ( 191 | ); 192 | name = ReactNativeBaiduVoiceRecognition; 193 | productName = ReactNativeBaiduVoiceRecognizition; 194 | productReference = 35366A181D2FA04200DB398A /* libReactNativeBaiduVoiceRecognition.a */; 195 | productType = "com.apple.product-type.library.static"; 196 | }; 197 | /* End PBXNativeTarget section */ 198 | 199 | /* Begin PBXProject section */ 200 | 35366A101D2FA04200DB398A /* Project object */ = { 201 | isa = PBXProject; 202 | attributes = { 203 | LastUpgradeCheck = 0730; 204 | ORGANIZATIONNAME = com.ludafa; 205 | TargetAttributes = { 206 | 35366A171D2FA04200DB398A = { 207 | CreatedOnToolsVersion = 7.3.1; 208 | DevelopmentTeam = 9N4RDS7YY4; 209 | }; 210 | }; 211 | }; 212 | buildConfigurationList = 35366A131D2FA04200DB398A /* Build configuration list for PBXProject "ReactNativeBaiduVoiceRecognition" */; 213 | compatibilityVersion = "Xcode 3.2"; 214 | developmentRegion = English; 215 | hasScannedForEncodings = 0; 216 | knownRegions = ( 217 | en, 218 | ); 219 | mainGroup = 35366A0F1D2FA04200DB398A; 220 | productRefGroup = 35366A191D2FA04200DB398A /* Products */; 221 | projectDirPath = ""; 222 | projectRoot = ""; 223 | targets = ( 224 | 35366A171D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition */, 225 | ); 226 | }; 227 | /* End PBXProject section */ 228 | 229 | /* Begin PBXSourcesBuildPhase section */ 230 | 35366A141D2FA04200DB398A /* Sources */ = { 231 | isa = PBXSourcesBuildPhase; 232 | buildActionMask = 2147483647; 233 | files = ( 234 | 35366A1E1D2FA04200DB398A /* ReactNativeBaiduVoiceRecognition.m in Sources */, 235 | ); 236 | runOnlyForDeploymentPostprocessing = 0; 237 | }; 238 | /* End PBXSourcesBuildPhase section */ 239 | 240 | /* Begin XCBuildConfiguration section */ 241 | 35366A1F1D2FA04200DB398A /* Debug */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | ALWAYS_SEARCH_USER_PATHS = NO; 245 | CLANG_ANALYZER_NONNULL = YES; 246 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 247 | CLANG_CXX_LIBRARY = "libc++"; 248 | CLANG_ENABLE_MODULES = YES; 249 | CLANG_ENABLE_OBJC_ARC = YES; 250 | CLANG_WARN_BOOL_CONVERSION = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 253 | CLANG_WARN_EMPTY_BODY = YES; 254 | CLANG_WARN_ENUM_CONVERSION = YES; 255 | CLANG_WARN_INT_CONVERSION = YES; 256 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 257 | CLANG_WARN_UNREACHABLE_CODE = YES; 258 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 259 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 260 | COPY_PHASE_STRIP = NO; 261 | DEBUG_INFORMATION_FORMAT = dwarf; 262 | ENABLE_STRICT_OBJC_MSGSEND = YES; 263 | ENABLE_TESTABILITY = YES; 264 | GCC_C_LANGUAGE_STANDARD = gnu99; 265 | GCC_DYNAMIC_NO_PIC = NO; 266 | GCC_NO_COMMON_BLOCKS = YES; 267 | GCC_OPTIMIZATION_LEVEL = 0; 268 | GCC_PREPROCESSOR_DEFINITIONS = ( 269 | "DEBUG=1", 270 | "$(inherited)", 271 | ); 272 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 273 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 274 | GCC_WARN_UNDECLARED_SELECTOR = YES; 275 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 276 | GCC_WARN_UNUSED_FUNCTION = YES; 277 | GCC_WARN_UNUSED_VARIABLE = YES; 278 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 279 | MTL_ENABLE_DEBUG_INFO = YES; 280 | ONLY_ACTIVE_ARCH = YES; 281 | SDKROOT = iphoneos; 282 | }; 283 | name = Debug; 284 | }; 285 | 35366A201D2FA04200DB398A /* Release */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | CLANG_ANALYZER_NONNULL = YES; 290 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 291 | CLANG_CXX_LIBRARY = "libc++"; 292 | CLANG_ENABLE_MODULES = YES; 293 | CLANG_ENABLE_OBJC_ARC = YES; 294 | CLANG_WARN_BOOL_CONVERSION = YES; 295 | CLANG_WARN_CONSTANT_CONVERSION = YES; 296 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 297 | CLANG_WARN_EMPTY_BODY = YES; 298 | CLANG_WARN_ENUM_CONVERSION = YES; 299 | CLANG_WARN_INT_CONVERSION = YES; 300 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 301 | CLANG_WARN_UNREACHABLE_CODE = YES; 302 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 303 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 304 | COPY_PHASE_STRIP = NO; 305 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 306 | ENABLE_NS_ASSERTIONS = NO; 307 | ENABLE_STRICT_OBJC_MSGSEND = YES; 308 | GCC_C_LANGUAGE_STANDARD = gnu99; 309 | GCC_NO_COMMON_BLOCKS = YES; 310 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 311 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 312 | GCC_WARN_UNDECLARED_SELECTOR = YES; 313 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 314 | GCC_WARN_UNUSED_FUNCTION = YES; 315 | GCC_WARN_UNUSED_VARIABLE = YES; 316 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 317 | MTL_ENABLE_DEBUG_INFO = NO; 318 | SDKROOT = iphoneos; 319 | VALIDATE_PRODUCT = YES; 320 | }; 321 | name = Release; 322 | }; 323 | 35366A221D2FA04200DB398A /* Debug */ = { 324 | isa = XCBuildConfiguration; 325 | buildSettings = { 326 | HEADER_SEARCH_PATHS = ( 327 | "$(SRCROOT)/../../react-native/React/**", 328 | "$(SRCROOT)/../Example/node_modules/react-native/React/**", 329 | ); 330 | LIBRARY_SEARCH_PATHS = ( 331 | "$(inherited)", 332 | "$(PROJECT_DIR)/BaiduVoiceSDK/BDSClientLib", 333 | ); 334 | OTHER_LDFLAGS = ( 335 | "-ObjC", 336 | "-llibiconv", 337 | "-llibc++", 338 | "-llibz", 339 | "-llibstdc++", 340 | ); 341 | PRODUCT_NAME = ReactNativeBaiduVoiceRecognition; 342 | SKIP_INSTALL = YES; 343 | }; 344 | name = Debug; 345 | }; 346 | 35366A231D2FA04200DB398A /* Release */ = { 347 | isa = XCBuildConfiguration; 348 | buildSettings = { 349 | HEADER_SEARCH_PATHS = ( 350 | "$(SRCROOT)/../../react-native/React/**", 351 | "$(SRCROOT)/../Example/node_modules/react-native/React/**", 352 | ); 353 | LIBRARY_SEARCH_PATHS = ( 354 | "$(inherited)", 355 | "$(PROJECT_DIR)/BaiduVoiceSDK/BDSClientLib", 356 | ); 357 | OTHER_LDFLAGS = ( 358 | "-ObjC", 359 | "-llibiconv", 360 | "-llibc++", 361 | "-llibz", 362 | "-llibstdc++", 363 | ); 364 | PRODUCT_NAME = ReactNativeBaiduVoiceRecognition; 365 | SKIP_INSTALL = YES; 366 | }; 367 | name = Release; 368 | }; 369 | /* End XCBuildConfiguration section */ 370 | 371 | /* Begin XCConfigurationList section */ 372 | 35366A131D2FA04200DB398A /* Build configuration list for PBXProject "ReactNativeBaiduVoiceRecognition" */ = { 373 | isa = XCConfigurationList; 374 | buildConfigurations = ( 375 | 35366A1F1D2FA04200DB398A /* Debug */, 376 | 35366A201D2FA04200DB398A /* Release */, 377 | ); 378 | defaultConfigurationIsVisible = 0; 379 | defaultConfigurationName = Release; 380 | }; 381 | 35366A211D2FA04200DB398A /* Build configuration list for PBXNativeTarget "ReactNativeBaiduVoiceRecognition" */ = { 382 | isa = XCConfigurationList; 383 | buildConfigurations = ( 384 | 35366A221D2FA04200DB398A /* Debug */, 385 | 35366A231D2FA04200DB398A /* Release */, 386 | ); 387 | defaultConfigurationIsVisible = 0; 388 | defaultConfigurationName = Release; 389 | }; 390 | /* End XCConfigurationList section */ 391 | }; 392 | rootObject = 35366A101D2FA04200DB398A /* Project object */; 393 | } 394 | -------------------------------------------------------------------------------- /ios/ReactNativeBaiduVoiceRecognition.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/ReactNativeBaiduVoiceRecognition.xcodeproj/project.xcworkspace/xcuserdata/leon.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-melon/react-native-baidu-voice-recognition/337752938739d5c0f3784fe3b99ee9bce3210a93/ios/ReactNativeBaiduVoiceRecognition.xcodeproj/project.xcworkspace/xcuserdata/leon.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ios/ReactNativeBaiduVoiceRecognition.xcodeproj/xcuserdata/leon.xcuserdatad/xcschemes/ReactNativeBaiduVoiceRecognizition.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /ios/ReactNativeBaiduVoiceRecognition.xcodeproj/xcuserdata/leon.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ReactNativeBaiduVoiceRecognizition.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 35366A171D2FA04200DB398A 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ios/ReactNativeBaiduVoiceRecognizition/ReactNativeBaiduVoiceRecognition.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReactNativeBaiduVoiceRecognizition.h 3 | // ReactNativeBaiduVoiceRecognizition 4 | // 5 | // Created by leon on 16/7/8. 6 | // Copyright © 2016年 com.ludafa. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RCTBridgeModule.h" 11 | #import "BDSEventManager.h" 12 | 13 | @interface ReactNativeBaiduVoiceRecognition : NSObject 14 | 15 | @property NSDictionary *options; 16 | @property BDSEventManager *asrEventManager; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /ios/ReactNativeBaiduVoiceRecognizition/ReactNativeBaiduVoiceRecognition.m: -------------------------------------------------------------------------------- 1 | // 2 | // ReactNativeBaiduVoiceRecognizition.m 3 | // ReactNativeBaiduVoiceRecognizition 4 | // 5 | // Created by leon on 16/7/8. 6 | // Copyright © 2016年 com.ludafa. All rights reserved. 7 | // 8 | 9 | #import "RCTEventDispatcher.h" 10 | #import "ReactNativeBaiduVoiceRecognition.h" 11 | 12 | #import "BDSEventManager.h" 13 | #import "BDSASRParameters.h" 14 | #import "BDSASRDefines.h" 15 | 16 | NSString *jsEventName = @"ReactNativeBaiduVoiceRecognition"; 17 | 18 | @implementation ReactNativeBaiduVoiceRecognition 19 | 20 | RCT_EXPORT_MODULE(); 21 | 22 | @synthesize bridge = _bridge; 23 | 24 | RCT_EXPORT_METHOD(startRecognition:(NSString*)apiKey 25 | secretKey:(NSString*)secretKey) 26 | { 27 | 28 | self.asrEventManager = [BDSEventManager createEventManagerWithName:BDS_ASR_NAME]; 29 | 30 | [self.asrEventManager setDelegate:self]; 31 | [self.asrEventManager setParameter:@[apiKey, secretKey] forKey:BDS_ASR_API_SECRET_KEYS]; 32 | [self.asrEventManager setParameter:nil forKey:BDS_ASR_AUDIO_FILE_PATH]; 33 | [self.asrEventManager setParameter:nil forKey:BDS_ASR_AUDIO_INPUT_STREAM]; 34 | [self.asrEventManager setParameter:@(NO) forKey:BDS_ASR_DISABLE_AUDIO_OPERATION]; 35 | [self.asrEventManager sendCommand:BDS_ASR_CMD_START]; 36 | 37 | } 38 | 39 | RCT_EXPORT_METHOD(finishRecognition) { 40 | 41 | if (self.asrEventManager) { 42 | [self.asrEventManager sendCommand:BDS_ASR_CMD_STOP]; 43 | } 44 | 45 | } 46 | 47 | RCT_EXPORT_METHOD(cancelRecognition) { 48 | 49 | if (self.asrEventManager) { 50 | [self.asrEventManager sendCommand:BDS_ASR_CMD_CANCEL]; 51 | } 52 | 53 | } 54 | 55 | - (void)VoiceRecognitionClientWorkStatus:(int)workStatus obj:(id)aObj 56 | 57 | { 58 | // 抛弃新录音这个事件,其他事件回调给 js 59 | switch (workStatus) { 60 | case EVoiceRecognitionClientWorkStatusNewRecordData: 61 | break; 62 | case EVoiceRecognitionClientWorkStatusMeterLevel: 63 | case EVoiceRecognitionClientWorkStatusStartWorkIng: 64 | case EVoiceRecognitionClientWorkStatusStart: 65 | case EVoiceRecognitionClientWorkStatusEnd: 66 | case EVoiceRecognitionClientWorkStatusFlushData: 67 | case EVoiceRecognitionClientWorkStatusFinish: 68 | case EVoiceRecognitionClientWorkStatusCancel: 69 | case EVoiceRecognitionClientWorkStatusError: 70 | case EVoiceRecognitionClientWorkStatusLoaded: 71 | case EVoiceRecognitionClientWorkStatusUnLoaded: 72 | default: { 73 | 74 | NSString *data = [self getDescriptionForDic:aObj]; 75 | NSDictionary *body = @{ 76 | @"status": [NSNumber numberWithInt:workStatus], 77 | @"data": data}; 78 | 79 | [self.bridge.eventDispatcher sendAppEventWithName:jsEventName 80 | body:body]; 81 | break; 82 | } 83 | 84 | } 85 | 86 | } 87 | 88 | - (NSString *)getDescriptionForDic:(id)obj 89 | { 90 | 91 | if ([obj isKindOfClass:[NSDictionary class]]) { 92 | NSData *data = [NSJSONSerialization dataWithJSONObject:obj 93 | options:NSJSONWritingPrettyPrinted 94 | error:nil]; 95 | return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 96 | } 97 | 98 | if ([obj isKindOfClass:[NSNumber class]]) { 99 | return obj; 100 | } 101 | 102 | if ([obj isKindOfClass:[NSError class]]) { 103 | return [obj localizedDescription]; 104 | } 105 | 106 | 107 | return [NSNull null]; 108 | } 109 | 110 | - (NSDictionary *)constantsToExport 111 | { 112 | 113 | return @{ 114 | 115 | 116 | // 回调事件名 117 | @"VoiceRecognitionEventName": @"ReactNativeBaiduVoiceRecognition", 118 | 119 | // 识别相关的工作状态 120 | // 识别工作开始,开始采集及处理数据 121 | @"EVoiceRecognitionClientWorkStatusStartWorkIng": @(EVoiceRecognitionClientWorkStatusStartWorkIng), 122 | // 检测到用户开始说话 123 | @"EVoiceRecognitionClientWorkStatusStart": @(EVoiceRecognitionClientWorkStatusStart), 124 | // 本地声音采集结束结束,等待识别结果返回并结束录音 125 | @"EVoiceRecognitionClientWorkStatusEnd": @(EVoiceRecognitionClientWorkStatusEnd), 126 | // 录音数据回调 127 | @"EVoiceRecognitionClientWorkStatusNewRecordData": @(EVoiceRecognitionClientWorkStatusNewRecordData), 128 | // 连续上屏 129 | @"EVoiceRecognitionClientWorkStatusFlushData": @(EVoiceRecognitionClientWorkStatusFlushData), 130 | // 语音识别功能完成,服务器返回正确结果 131 | @"EVoiceRecognitionClientWorkStatusFinish": @(EVoiceRecognitionClientWorkStatusFinish), 132 | // 当前音量回调 133 | @"EVoiceRecognitionClientWorkStatusMeterLevel": @(EVoiceRecognitionClientWorkStatusMeterLevel), 134 | // 用户取消 135 | @"EVoiceRecognitionClientWorkStatusCancel": @(EVoiceRecognitionClientWorkStatusCancel), 136 | // 发生错误,详情见VoiceRecognitionClientErrorInfo接口通知 137 | @"EVoiceRecognitionClientWorkStatusError": @(EVoiceRecognitionClientWorkStatusError), 138 | 139 | // 离线引擎状态 140 | // 离线引擎加载完成 141 | @"EVoiceRecognitionClientWorkStatusLoaded": @(EVoiceRecognitionClientWorkStatusLoaded), 142 | // 离线引擎卸载完成 143 | @"EVoiceRecognitionClientWorkStatusUnLoaded": @(EVoiceRecognitionClientWorkStatusUnLoaded) 144 | 145 | }; 146 | 147 | } 148 | 149 | @end 150 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-baidu-voice-recognition", 3 | "version": "1.0.0", 4 | "description": "baidu voice recognition sdk for react native", 5 | "main": "index.js", 6 | "directories": { 7 | "doc": "doc" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "http://gitlab.baidu.com/lupengyu/react-native-bds.git" 15 | }, 16 | "keywords": [ 17 | "baidu", 18 | "yuyin", 19 | "voice", 20 | "recognition", 21 | "react-native" 22 | ], 23 | "rnpm": { 24 | "ios": { 25 | "sharedLibraries": [ 26 | "CoreLocation.framework", 27 | "CoreTelephony.framework", 28 | "CFNetwork.framework", 29 | "GLKit.framework", 30 | "SystemConfiguration.framework", 31 | "AudioToolbox.framework", 32 | "AVFoundation.framework", 33 | "libstdc++.6.0.9.tbd", 34 | "libiconv.2.4.0.tbd", 35 | "libc++.tbd", 36 | "libz.1.2.5.tbd" 37 | ] 38 | } 39 | }, 40 | "author": "leonlu ", 41 | "license": "ISC" 42 | } 43 | --------------------------------------------------------------------------------