Browse Source
同声翻译在密钥未下发时不再反复挂微软听写,避免安卓栈溢出。文本和同声在有 SparkChain 密钥时优先走端上讯飞。 Co-authored-by: Cursor <cursoragent@cursor.com>along-test
125 changed files with 5223 additions and 113 deletions
@ -0,0 +1,18 @@ |
|||
import 'package:flutter_dotenv/flutter_dotenv.dart'; |
|||
|
|||
import 'network/dio_manager.dart'; |
|||
|
|||
/// 连着测试服时,AI 只走科大讯飞。微软、阿里、字节、谷歌、灵犀都不要发请求。 |
|||
/// |
|||
/// 正式域名不进这把锁。密钥还在本地缓存里也不许拿去调别家。 |
|||
bool get aiOnlyIflytek { |
|||
final hosts = <String>[ |
|||
DioManager().baseUrl, |
|||
dotenv.env['SERVER_URL'] ?? '', |
|||
dotenv.env['HW_SERVER_URL'] ?? '', |
|||
]; |
|||
for (final host in hosts) { |
|||
if (host.contains('ym-dev.ymaikj.com')) return true; |
|||
} |
|||
return false; |
|||
} |
|||
@ -0,0 +1,174 @@ |
|||
import 'dart:async'; |
|||
import 'dart:typed_data'; |
|||
|
|||
import 'package:sparkchain/sparkchain.dart'; |
|||
|
|||
import '../../core/utils/logger.dart'; |
|||
import '../models/appconfig.dart'; |
|||
|
|||
/// 端上讯飞翻译。没配密钥就返回 null,调用方继续走原来的服务端翻译。 |
|||
class SparkChainSession { |
|||
SparkChainSession._(); |
|||
|
|||
static const _tag = 'SparkChain'; |
|||
static bool _ready = false; |
|||
static bool _eventsAttached = false; |
|||
static bool listening = false; |
|||
static int _seq = 0; |
|||
static final Map<String, Completer<Map<String, dynamic>>> _waiters = {}; |
|||
static final Map<String, void Function(Uint8List pcm, bool isFinal)> _ttsHandlers = {}; |
|||
static final Map<String, Completer<void>> _ttsWaiters = {}; |
|||
|
|||
/// 听写结果。只在 [startListen] 成功之后、[stopListen] 之前有意义。 |
|||
static void Function(Map<String, dynamic> event)? asrListener; |
|||
|
|||
static Future<bool> ensure() async { |
|||
if (_ready) return true; |
|||
final appId = AppConfig.cred('sparkchain', 'app_id', 'SPARKCHAIN_APP_ID'); |
|||
final apiKey = AppConfig.cred('sparkchain', 'api_key', 'SPARKCHAIN_API_KEY'); |
|||
final apiSecret = |
|||
AppConfig.cred('sparkchain', 'api_secret', 'SPARKCHAIN_API_SECRET'); |
|||
if (appId == null || apiKey == null || apiSecret == null) { |
|||
return false; |
|||
} |
|||
if (!_eventsAttached) { |
|||
_eventsAttached = true; |
|||
SparkChain.events.listen(_onEvent); |
|||
} |
|||
final apiType = |
|||
int.tryParse(AppConfig.cred('sparkchain', 'api_type', 'SPARKCHAIN_API_TYPE') ?? '') ?? |
|||
1; |
|||
final code = await SparkChain.init( |
|||
appId: appId, |
|||
apiKey: apiKey, |
|||
apiSecret: apiSecret, |
|||
apiType: apiType, |
|||
); |
|||
Logger.i(_tag, 'init code=$code apiType=$apiType'); |
|||
_ready = code == 0; |
|||
return _ready; |
|||
} |
|||
|
|||
static void _onEvent(Map<String, dynamic> event) { |
|||
final id = event['id']?.toString() ?? ''; |
|||
final kind = event['kind']; |
|||
if (kind == 'its' || (kind == 'error' && event['where'] == 'its')) { |
|||
final waiter = _waiters[id]; |
|||
if (waiter != null && !waiter.isCompleted) waiter.complete(event); |
|||
} |
|||
if (kind == 'asr' || (kind == 'error' && event['where'] == 'asr')) { |
|||
asrListener?.call(event); |
|||
} |
|||
if (kind == 'tts' || (kind == 'error' && event['where'] == 'tts')) { |
|||
_onTts(id, event); |
|||
} |
|||
} |
|||
|
|||
static void _onTts(String id, Map<String, dynamic> event) { |
|||
if (event['kind'] == 'error') { |
|||
_ttsHandlers.remove(id); |
|||
final waiter = _ttsWaiters.remove(id); |
|||
if (waiter != null && !waiter.isCompleted) { |
|||
waiter.completeError(StateError('${event['code']}')); |
|||
} |
|||
return; |
|||
} |
|||
final raw = event['pcm']; |
|||
final pcm = raw is Uint8List ? raw : Uint8List(0); |
|||
_ttsHandlers[id]?.call(pcm, event['final'] == true); |
|||
if (event['final'] == true) { |
|||
_ttsHandlers.remove(id); |
|||
final waiter = _ttsWaiters.remove(id); |
|||
if (waiter != null && !waiter.isCompleted) waiter.complete(); |
|||
} |
|||
} |
|||
|
|||
/// 只听 [lang] 这一种。ga 走实时转写,其余走听写。SDK 不自己开麦。 |
|||
static Future<bool> startListen(String lang) async { |
|||
if (!await ensure()) return false; |
|||
final code = await SparkChain.startListen(id: 'listen', lang: sparkChainShortCode(lang)); |
|||
listening = code == 0; |
|||
if (!listening) { |
|||
Logger.w(_tag, 'startListen 失败 code=$code'); |
|||
} |
|||
return listening; |
|||
} |
|||
|
|||
static void write(Uint8List pcm) { |
|||
if (!listening || pcm.isEmpty) return; |
|||
unawaited(SparkChain.write(pcm)); |
|||
} |
|||
|
|||
static Future<void> stopListen() async { |
|||
if (!listening) return; |
|||
listening = false; |
|||
asrListener = null; |
|||
try { |
|||
await SparkChain.stopListen(); |
|||
} catch (e) { |
|||
Logger.w(_tag, 'stopListen: $e'); |
|||
} |
|||
} |
|||
|
|||
/// 合成一段。PCM 按到达顺序交给 [onPcm],整段结束或失败才返回。 |
|||
static Future<void> speak({ |
|||
required String lang, |
|||
required String text, |
|||
required void Function(Uint8List pcm, bool isFinal) onPcm, |
|||
}) async { |
|||
if (!await ensure()) { |
|||
throw StateError('sparkchain not ready'); |
|||
} |
|||
final id = 'tts-${++_seq}'; |
|||
final waiter = Completer<void>(); |
|||
_ttsWaiters[id] = waiter; |
|||
_ttsHandlers[id] = onPcm; |
|||
final code = await SparkChain.speak( |
|||
id: id, |
|||
lang: sparkChainShortCode(lang), |
|||
text: text, |
|||
); |
|||
if (code != 0) { |
|||
_ttsHandlers.remove(id); |
|||
_ttsWaiters.remove(id); |
|||
throw StateError('speak $code'); |
|||
} |
|||
await waiter.future.timeout(const Duration(seconds: 20)); |
|||
} |
|||
|
|||
/// 短码 zh / en / ga。失败返回 null,不抛。 |
|||
static Future<String?> translate({ |
|||
required String from, |
|||
required String to, |
|||
required String text, |
|||
}) async { |
|||
if (!await ensure()) return null; |
|||
final id = '${++_seq}'; |
|||
final waiter = Completer<Map<String, dynamic>>(); |
|||
_waiters[id] = waiter; |
|||
try { |
|||
final code = await SparkChain.translate( |
|||
id: id, |
|||
from: sparkChainShortCode(from), |
|||
to: sparkChainShortCode(to), |
|||
text: text, |
|||
); |
|||
if (code != 0) { |
|||
Logger.w(_tag, 'translate 启动失败 code=$code'); |
|||
return null; |
|||
} |
|||
final event = await waiter.future.timeout(const Duration(seconds: 12)); |
|||
if (event['kind'] != 'its') { |
|||
Logger.w(_tag, 'translate 失败 code=${event['code']} sid=${event['sid']}'); |
|||
return null; |
|||
} |
|||
final out = (event['text'] as String?)?.trim() ?? ''; |
|||
return out.isEmpty ? null : out; |
|||
} on TimeoutException { |
|||
Logger.w(_tag, 'translate 超时'); |
|||
return null; |
|||
} finally { |
|||
_waiters.remove(id); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
plugins { |
|||
id("com.android.library") |
|||
id("org.jetbrains.kotlin.android") |
|||
} |
|||
|
|||
android { |
|||
namespace = "com.yunqiinnovation.sparkchain" |
|||
compileSdk = 35 |
|||
|
|||
defaultConfig { |
|||
minSdk = 21 |
|||
consumerProguardFiles("consumer-rules.pro") |
|||
} |
|||
|
|||
compileOptions { |
|||
sourceCompatibility = JavaVersion.VERSION_11 |
|||
targetCompatibility = JavaVersion.VERSION_11 |
|||
} |
|||
|
|||
kotlinOptions { |
|||
jvmTarget = "11" |
|||
} |
|||
|
|||
sourceSets.getByName("main").jniLibs.srcDirs("src/main/jniLibs") |
|||
} |
|||
|
|||
// 插件自己会打成 AAR,不能再 implementation 本地 AAR,否则 release 打包直接失败。 |
|||
// SparkChain.aar / Codec.aar 已拆成 libs/*.jar、jniLibs 和 assets。 |
|||
dependencies { |
|||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) |
|||
} |
|||
@ -0,0 +1 @@ |
|||
-keep class com.iflytek.sparkchain.** { *; } |
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@ |
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> |
|||
<uses-permission android:name="android.permission.INTERNET" /> |
|||
</manifest> |
|||
@ -0,0 +1,17 @@ |
|||
{ |
|||
"supplier":{ |
|||
"vivo":{ |
|||
"appid":"" |
|||
}, |
|||
"xiaomi":{ |
|||
"appid":"" |
|||
}, |
|||
"huawei":{ |
|||
"appid":"103256863" |
|||
}, |
|||
"oppo":{ |
|||
|
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,334 @@ |
|||
package com.yunqiinnovation.sparkchain |
|||
|
|||
import android.content.Context |
|||
import android.os.Handler |
|||
import android.os.Looper |
|||
import com.iflytek.sparkchain.core.SparkChain |
|||
import com.iflytek.sparkchain.core.SparkChainConfig |
|||
import com.iflytek.sparkchain.core.asr.ASR |
|||
import com.iflytek.sparkchain.core.asr.AsrCallbacks |
|||
import com.iflytek.sparkchain.core.asr.AudioAttributes |
|||
import com.iflytek.sparkchain.core.asr.RegionType |
|||
import com.iflytek.sparkchain.core.common.ApiType |
|||
import com.iflytek.sparkchain.core.its.ITS |
|||
import com.iflytek.sparkchain.core.its.ITSCallbacks |
|||
import com.iflytek.sparkchain.core.its.TransType |
|||
import com.iflytek.sparkchain.core.rtasr.RTASR |
|||
import com.iflytek.sparkchain.core.rtasr.RTASRCallbacks |
|||
import com.iflytek.sparkchain.core.tts.OnlineTTS |
|||
import com.iflytek.sparkchain.core.tts.TTS |
|||
import com.iflytek.sparkchain.core.tts.TTSCallbacks |
|||
import io.flutter.embedding.engine.plugins.FlutterPlugin |
|||
import io.flutter.plugin.common.EventChannel |
|||
import io.flutter.plugin.common.MethodCall |
|||
import io.flutter.plugin.common.MethodChannel |
|||
import java.util.concurrent.Executors |
|||
|
|||
/// 讯飞海外 SDK。不自己开麦,PCM 由调用方 write 进来。 |
|||
class SparkChainPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, EventChannel.StreamHandler { |
|||
private val main = Handler(Looper.getMainLooper()) |
|||
// 听写的 write 不能排在翻译后面:arun 若卡住,耳机麦帧会在队列里过期。 |
|||
private val audio = Executors.newSingleThreadExecutor() |
|||
private val cloud = Executors.newSingleThreadExecutor() |
|||
private var channel: MethodChannel? = null |
|||
private var events: EventChannel? = null |
|||
private var sink: EventChannel.EventSink? = null |
|||
private var appContext: Context? = null |
|||
private var ready = false |
|||
|
|||
private var asr: ASR? = null |
|||
private var rtasr: RTASR? = null |
|||
private var its: ITS? = null |
|||
private var tts: OnlineTTS? = null |
|||
|
|||
private val asrCallbacks = object : AsrCallbacks { |
|||
override fun onResult(result: ASR.ASRResult, usrTag: Any?) { |
|||
val text = result.bestMatchText ?: "" |
|||
emit( |
|||
mapOf( |
|||
"kind" to "asr", |
|||
"id" to (usrTag?.toString() ?: ""), |
|||
"text" to text, |
|||
"final" to (result.status == 2), |
|||
"sid" to (result.sid ?: ""), |
|||
), |
|||
) |
|||
} |
|||
|
|||
override fun onError(error: ASR.ASRError, usrTag: Any?) { |
|||
emit( |
|||
mapOf( |
|||
"kind" to "error", |
|||
"where" to "asr", |
|||
"id" to (usrTag?.toString() ?: ""), |
|||
"code" to error.code, |
|||
"message" to (error.errMsg ?: ""), |
|||
"sid" to (error.sid ?: ""), |
|||
), |
|||
) |
|||
} |
|||
} |
|||
|
|||
private val rtasrCallbacks = object : RTASRCallbacks { |
|||
override fun onResult(result: RTASR.RtAsrResult, usrTag: Any?) { |
|||
val status = result.status |
|||
emit( |
|||
mapOf( |
|||
"kind" to "asr", |
|||
"id" to (usrTag?.toString() ?: ""), |
|||
"text" to (result.data ?: ""), |
|||
"final" to (status == 2 || status == 3), |
|||
"sid" to (result.sid ?: ""), |
|||
), |
|||
) |
|||
} |
|||
|
|||
override fun onError(error: RTASR.RtAsrError, usrTag: Any?) { |
|||
emit( |
|||
mapOf( |
|||
"kind" to "error", |
|||
"where" to "asr", |
|||
"id" to (usrTag?.toString() ?: ""), |
|||
"code" to error.code, |
|||
"message" to (error.errMsg ?: ""), |
|||
"sid" to (error.sid ?: ""), |
|||
), |
|||
) |
|||
} |
|||
} |
|||
|
|||
private val itsCallbacks = object : ITSCallbacks { |
|||
override fun onResult(result: ITS.ITSResult, usrTag: Any?) { |
|||
val dst = result.transResult?.dst ?: "" |
|||
emit( |
|||
mapOf( |
|||
"kind" to "its", |
|||
"id" to (usrTag?.toString() ?: ""), |
|||
"text" to dst, |
|||
"sid" to (result.sid ?: ""), |
|||
), |
|||
) |
|||
} |
|||
|
|||
override fun onError(error: ITS.ITSError, usrTag: Any?) { |
|||
emit( |
|||
mapOf( |
|||
"kind" to "error", |
|||
"where" to "its", |
|||
"id" to (usrTag?.toString() ?: ""), |
|||
"code" to error.code, |
|||
"message" to (error.errMsg ?: ""), |
|||
"sid" to (error.sid ?: ""), |
|||
), |
|||
) |
|||
} |
|||
} |
|||
|
|||
private val ttsCallbacks = object : TTSCallbacks { |
|||
override fun onResult(result: TTS.TTSResult, usrTag: Any?) { |
|||
val audio = result.data |
|||
emit( |
|||
mapOf( |
|||
"kind" to "tts", |
|||
"id" to (usrTag?.toString() ?: ""), |
|||
"pcm" to (audio ?: ByteArray(0)), |
|||
"final" to (result.status == 2), |
|||
"sid" to (result.sid ?: ""), |
|||
), |
|||
) |
|||
} |
|||
|
|||
override fun onError(error: TTS.TTSError, usrTag: Any?) { |
|||
emit( |
|||
mapOf( |
|||
"kind" to "error", |
|||
"where" to "tts", |
|||
"id" to (usrTag?.toString() ?: ""), |
|||
"code" to error.code, |
|||
"message" to (error.errMsg ?: ""), |
|||
"sid" to (error.sid ?: ""), |
|||
), |
|||
) |
|||
} |
|||
} |
|||
|
|||
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { |
|||
appContext = binding.applicationContext |
|||
channel = MethodChannel(binding.binaryMessenger, "sparkchain").also { |
|||
it.setMethodCallHandler(this) |
|||
} |
|||
events = EventChannel(binding.binaryMessenger, "sparkchain/events").also { |
|||
it.setStreamHandler(this) |
|||
} |
|||
} |
|||
|
|||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { |
|||
channel?.setMethodCallHandler(null) |
|||
events?.setStreamHandler(null) |
|||
channel = null |
|||
events = null |
|||
sink = null |
|||
} |
|||
|
|||
override fun onListen(arguments: Any?, eventSink: EventChannel.EventSink) { |
|||
sink = eventSink |
|||
} |
|||
|
|||
override fun onCancel(arguments: Any?) { |
|||
sink = null |
|||
} |
|||
|
|||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { |
|||
when (call.method) { |
|||
"init" -> cloud.execute { |
|||
val code = doInit(call) |
|||
main.post { result.success(code) } |
|||
} |
|||
"translate" -> cloud.execute { |
|||
val code = doTranslate(call) |
|||
main.post { result.success(code) } |
|||
} |
|||
"speak" -> cloud.execute { |
|||
val code = doSpeak(call) |
|||
main.post { result.success(code) } |
|||
} |
|||
"startListen" -> audio.execute { |
|||
val code = doStartListen(call) |
|||
main.post { result.success(code) } |
|||
} |
|||
"write" -> audio.execute { |
|||
val pcm = call.argument<ByteArray>("pcm") |
|||
val code = when { |
|||
rtasr != null && pcm != null -> rtasr!!.write(pcm) |
|||
asr != null && pcm != null -> asr!!.write(pcm) |
|||
else -> -1 |
|||
} |
|||
main.post { result.success(code) } |
|||
} |
|||
"stopListen" -> audio.execute { |
|||
rtasr?.stop(false) |
|||
asr?.stop(false) |
|||
rtasr = null |
|||
asr = null |
|||
main.post { result.success(0) } |
|||
} |
|||
"uninit" -> cloud.execute { |
|||
val code = if (ready) SparkChain.getInst().unInit() else 0 |
|||
ready = false |
|||
main.post { result.success(code) } |
|||
} |
|||
else -> result.notImplemented() |
|||
} |
|||
} |
|||
|
|||
private fun doInit(call: MethodCall): Int { |
|||
val ctx = appContext ?: return -1 |
|||
val appId = call.argument<String>("appId") ?: return -2 |
|||
val apiKey = call.argument<String>("apiKey") ?: return -2 |
|||
val apiSecret = call.argument<String>("apiSecret") ?: return -2 |
|||
if (ready) { |
|||
SparkChain.getInst().unInit() |
|||
ready = false |
|||
} |
|||
val apiType = when (call.argument<Int>("apiType") ?: 1) { |
|||
0 -> ApiType.TYPE_CH |
|||
2 -> ApiType.TYPE_EU |
|||
else -> ApiType.TYPE_SG |
|||
} |
|||
val work = java.io.File(ctx.filesDir, "sparkchain") |
|||
work.mkdirs() |
|||
val config = SparkChainConfig.builder() |
|||
.appID(appId) |
|||
.apiKey(apiKey) |
|||
.apiSecret(apiSecret) |
|||
.workDir(work.absolutePath) |
|||
.logLevel(3) |
|||
.apiType(apiType) |
|||
val code = SparkChain.getInst().init(ctx, config) |
|||
ready = code == 0 |
|||
return code |
|||
} |
|||
|
|||
/// GTRANS 的中文码是 zh-CN,爱尔兰语是 ga。听写中文码是 zh_cn,两套不要混。 |
|||
private fun itsCode(short: String): String = when (short) { |
|||
"zh" -> "zh-CN" |
|||
"en" -> "en" |
|||
"ga" -> "ga" |
|||
else -> short |
|||
} |
|||
|
|||
private fun asrCode(short: String): String = when (short) { |
|||
"zh" -> "zh_cn" |
|||
"en" -> "en_us" |
|||
else -> short |
|||
} |
|||
|
|||
private fun doTranslate(call: MethodCall): Int { |
|||
if (!ready) return -1 |
|||
val text = call.argument<String>("text") ?: return -2 |
|||
val id = call.argument<String>("id") ?: "" |
|||
val from = itsCode(call.argument<String>("from") ?: "zh") |
|||
val to = itsCode(call.argument<String>("to") ?: "en") |
|||
val engine = ITS(TransType.GTRANS) |
|||
engine.registerCallbacks(itsCallbacks) |
|||
engine.fromlanguage(from) |
|||
engine.tolanguage(to) |
|||
its = engine |
|||
return engine.arun(text, id) |
|||
} |
|||
|
|||
private fun doSpeak(call: MethodCall): Int { |
|||
if (!ready) return -1 |
|||
val text = call.argument<String>("text") ?: return -2 |
|||
val id = call.argument<String>("id") ?: "" |
|||
val lang = call.argument<String>("lang") ?: "zh" |
|||
val voice = call.argument<String>("voice") |
|||
val (region, vcn) = when (lang) { |
|||
"ga" -> RegionType.MSFT_TYPE to (voice ?: "ga-IE-OrlaNeural") |
|||
"en" -> null to (voice ?: "x_Catherine") |
|||
else -> null to (voice ?: "x_xiaoyan") |
|||
} |
|||
val engine = if (region != null) OnlineTTS(region, vcn) else OnlineTTS(vcn) |
|||
engine.aue("raw") |
|||
engine.registerCallbacks(ttsCallbacks) |
|||
tts = engine |
|||
return engine.aRun(text, id) |
|||
} |
|||
|
|||
private fun doStartListen(call: MethodCall): Int { |
|||
if (!ready) return -1 |
|||
rtasr?.stop(true) |
|||
asr?.stop(true) |
|||
rtasr = null |
|||
asr = null |
|||
val lang = call.argument<String>("lang") ?: "zh" |
|||
val id = call.argument<String>("id") ?: "" |
|||
if (lang == "ga") { |
|||
val engine = RTASR(null, RegionType.MSFT_TYPE) |
|||
engine.registerCallbacks(rtasrCallbacks) |
|||
engine.setParams("language_name", "ga-IE") |
|||
engine.OstEncoding("raw") |
|||
rtasr = engine |
|||
return engine.start(id) |
|||
} |
|||
val engine = ASR() |
|||
engine.registerCallbacks(asrCallbacks) |
|||
engine.language(asrCode(lang)) |
|||
engine.domain("iat") |
|||
engine.accent("mandarin") |
|||
if (lang == "zh") engine.dwa("wpgs") |
|||
val attr = AudioAttributes() |
|||
attr.sampleRate = 16000 |
|||
attr.encoding = "raw" |
|||
attr.channels = 1 |
|||
attr.bitdepth = 16 |
|||
asr = engine |
|||
// 带 AudioAttributes 的 start 只收 write 进来的 PCM,不让 SDK 自己开麦。 |
|||
return engine.start(attr, id) |
|||
} |
|||
|
|||
private fun emit(event: Map<String, Any>) { |
|||
val current = sink ?: return |
|||
main.post { current.success(event) } |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// swift-tools-version: 5.9 |
|||
import PackageDescription |
|||
|
|||
let package = Package( |
|||
name: "sparkchain", |
|||
platforms: [.iOS("13.0")], |
|||
products: [ |
|||
.library(name: "sparkchain", targets: ["sparkchain"]) |
|||
], |
|||
targets: [ |
|||
.target( |
|||
name: "SparkChainGlue", |
|||
dependencies: ["SparkChain"], |
|||
path: "Sources/glue", |
|||
publicHeadersPath: "include" |
|||
), |
|||
.target( |
|||
name: "sparkchain", |
|||
dependencies: ["SparkChain", "SparkChainGlue"], |
|||
path: "Sources/sparkchain" |
|||
), |
|||
.binaryTarget( |
|||
name: "SparkChain", |
|||
path: "SparkChain.xcframework" |
|||
) |
|||
] |
|||
) |
|||
@ -0,0 +1,21 @@ |
|||
#import "SparkChainGlue.h" |
|||
#import <SparkChain/SparkChain.h> |
|||
|
|||
int SparkChainGlueInit(NSString *appId, |
|||
NSString *apiKey, |
|||
NSString *apiSecret, |
|||
NSString *workDir, |
|||
int apiType) { |
|||
SparkChainConfig *config = [[SparkChainConfig alloc] init]; |
|||
config.appID(appId) |
|||
.apiKey(apiKey) |
|||
.apiSecret(apiSecret) |
|||
.workDir(workDir) |
|||
.logLevel(3) |
|||
.apiType(apiType); |
|||
return [[SparkChain getInst] init:config]; |
|||
} |
|||
|
|||
int SparkChainGlueUnInit(void) { |
|||
return [[SparkChain getInst] unInit]; |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
#import <Foundation/Foundation.h> |
|||
|
|||
/// SDK 的 init: 和方法名冲突,放在 ObjC 里调用。返回 0 表示成功。
|
|||
int SparkChainGlueInit(NSString *_Nonnull appId, |
|||
NSString *_Nonnull apiKey, |
|||
NSString *_Nonnull apiSecret, |
|||
NSString *_Nonnull workDir, |
|||
int apiType); |
|||
int SparkChainGlueUnInit(void); |
|||
@ -0,0 +1,270 @@ |
|||
import Flutter |
|||
import SparkChain |
|||
import SparkChainGlue |
|||
|
|||
/// 回调对象必须由插件强引用。SDK 里的 delegate 是 weak,局部变量会在 start 返回后被释放。 |
|||
@objc(SparkChainPlugin) |
|||
public final class SparkChainPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, |
|||
ASRCallbacks, RTASRCallback, ITSCallbacks, TTSCallbacks { |
|||
|
|||
private let channelName = "sparkchain" |
|||
private var events: FlutterEventSink? |
|||
private var ready = false |
|||
|
|||
private var asr: ASR? |
|||
private var rtasr: RTASR? |
|||
private var its: ITS? |
|||
private var tts: OnlineTTS? |
|||
|
|||
private let transOrder: [TransType] = [GOOGLETRANS, NIUTRANS, ITRANS_SG, ITRANS] |
|||
private var transIndex = 0 |
|||
private var pendingIts: [String: String] = [:] |
|||
|
|||
public static func register(with registrar: FlutterPluginRegistrar) { |
|||
let instance = SparkChainPlugin() |
|||
let channel = FlutterMethodChannel(name: "sparkchain", binaryMessenger: registrar.messenger()) |
|||
registrar.addMethodCallDelegate(instance, channel: channel) |
|||
let events = FlutterEventChannel(name: "sparkchain/events", binaryMessenger: registrar.messenger()) |
|||
events.setStreamHandler(instance) |
|||
} |
|||
|
|||
public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { |
|||
self.events = events |
|||
return nil |
|||
} |
|||
|
|||
public func onCancel(withArguments arguments: Any?) -> FlutterError? { |
|||
events = nil |
|||
return nil |
|||
} |
|||
|
|||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { |
|||
let args = call.arguments as? [String: Any] ?? [:] |
|||
switch call.method { |
|||
case "init": |
|||
result(doInit(args)) |
|||
case "translate": |
|||
result(doTranslate(args)) |
|||
case "speak": |
|||
result(doSpeak(args)) |
|||
case "startListen": |
|||
result(doStartListen(args)) |
|||
case "write": |
|||
let data = args["pcm"] as? FlutterStandardTypedData |
|||
if let rtasr, let data { |
|||
result(rtasr.write(data.data)) |
|||
} else if let asr, let data { |
|||
result(asr.write(data.data)) |
|||
} else { |
|||
result(-1) |
|||
} |
|||
case "stopListen": |
|||
rtasr?.stop(false) |
|||
asr?.stop(false) |
|||
rtasr = nil |
|||
asr = nil |
|||
result(0) |
|||
case "uninit": |
|||
let code = ready ? SparkChainGlueUnInit() : 0 |
|||
ready = false |
|||
result(code) |
|||
default: |
|||
result(FlutterMethodNotImplemented) |
|||
} |
|||
} |
|||
|
|||
private func doInit(_ args: [String: Any]) -> Int { |
|||
guard let appId = args["appId"] as? String, |
|||
let apiKey = args["apiKey"] as? String, |
|||
let apiSecret = args["apiSecret"] as? String else { |
|||
return -2 |
|||
} |
|||
if ready { |
|||
SparkChainGlueUnInit() |
|||
ready = false |
|||
} |
|||
let apiType = args["apiType"] as? Int ?? 1 |
|||
let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] |
|||
.appendingPathComponent("sparkchain", isDirectory: true) |
|||
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) |
|||
let code = SparkChainGlueInit(appId, apiKey, apiSecret, dir.path, Int32(apiType)) |
|||
ready = code == 0 |
|||
return Int(code) |
|||
} |
|||
|
|||
/// 大语种表用 zh-CN / ga。ITRANS 那张小表的中文是 cn,重试到 ITRANS 时再换。 |
|||
private func itsCode(_ short: String, smallTable: Bool) -> String { |
|||
switch short { |
|||
case "zh": return smallTable ? "cn" : "zh-CN" |
|||
case "en": return "en" |
|||
case "ga": return "ga" |
|||
default: return short |
|||
} |
|||
} |
|||
|
|||
private func doTranslate(_ args: [String: Any]) -> Int { |
|||
guard ready, let text = args["text"] as? String else { return ready ? -2 : -1 } |
|||
let id = args["id"] as? String ?? "" |
|||
let from = args["from"] as? String ?? "zh" |
|||
let to = args["to"] as? String ?? "en" |
|||
pendingIts[id] = "\(from)|\(to)|\(text)" |
|||
return runIts(id: id, from: from, to: to, text: text) |
|||
} |
|||
|
|||
private func runIts(id: String, from: String, to: String, text: String) -> Int { |
|||
let type = transOrder[transIndex] |
|||
let small = type == ITRANS || type == ITRANS_SG |
|||
let engine = ITS(formLanguage: itsCode(from, smallTable: small), toLanguage: itsCode(to, smallTable: small), type: type) |
|||
engine.callbacks = self |
|||
its = engine |
|||
return Int(engine.arun(text, userInfo: id)) |
|||
} |
|||
|
|||
private func doSpeak(_ args: [String: Any]) -> Int { |
|||
guard ready, let text = args["text"] as? String else { return ready ? -2 : -1 } |
|||
let id = args["id"] as? String ?? "" |
|||
let lang = args["lang"] as? String ?? "zh" |
|||
let voice = args["voice"] as? String |
|||
let engine: OnlineTTS |
|||
if lang == "ga" { |
|||
engine = OnlineTTS(region: RegionMSFT, vcn: voice ?? "ga-IE-OrlaNeural") |
|||
} else if lang == "en" { |
|||
engine = OnlineTTS(vcn: voice ?? "x_Catherine") |
|||
} else { |
|||
engine = OnlineTTS(vcn: voice ?? "x_xiaoyan") |
|||
} |
|||
engine.aue = "raw" |
|||
engine.cbs = self |
|||
tts = engine |
|||
return Int(engine.arun(text, userInfo: id)) |
|||
} |
|||
|
|||
private func doStartListen(_ args: [String: Any]) -> Int { |
|||
guard ready else { return -1 } |
|||
rtasr?.stop(true) |
|||
asr?.stop(true) |
|||
rtasr = nil |
|||
asr = nil |
|||
let lang = args["lang"] as? String ?? "zh" |
|||
let id = args["id"] as? String ?? "" |
|||
if lang == "ga" { |
|||
let engine = RTASR(region: RegionMSFT) |
|||
engine.delegate = self |
|||
engine.addStringParam("language_name", value: "ga-IE") |
|||
rtasr = engine |
|||
return Int(engine.start(withUserInfo: id)) |
|||
} |
|||
let engine = ASR() |
|||
engine.cbs = self |
|||
let code = lang == "en" ? "en_us" : "zh_cn" |
|||
engine.language(code) |
|||
engine.domain("iat") |
|||
engine.accent("mandarin") |
|||
if lang == "zh" { engine.dwa("wpgs") } |
|||
let attr = AudioAttributes() |
|||
attr.sampleRate = 16000 |
|||
attr.encoding = "raw" |
|||
attr.channels = 1 |
|||
attr.bitdepth = 16 |
|||
asr = engine |
|||
return Int(engine.start(attr, usrTag: id)) |
|||
} |
|||
|
|||
private func emit(_ event: [String: Any]) { |
|||
let sink = events |
|||
DispatchQueue.main.async { sink?(event) } |
|||
} |
|||
|
|||
public func onResult(_ result: ASRResult, usrTag: Any) { |
|||
emit([ |
|||
"kind": "asr", |
|||
"id": (usrTag as? String) ?? "", |
|||
"text": result.bestMatchText, |
|||
"final": result.status == 2, |
|||
"sid": result.sid, |
|||
]) |
|||
} |
|||
|
|||
public func onError(_ error: ASRError, usrTag: Any) { |
|||
emit([ |
|||
"kind": "error", |
|||
"where": "asr", |
|||
"id": (usrTag as? String) ?? "", |
|||
"code": error.code, |
|||
"message": error.errMsg, |
|||
"sid": error.sid, |
|||
]) |
|||
} |
|||
|
|||
public func onResult(_ result: RTASRResult, useInfo userInfo: Any?) { |
|||
let status = result.status |
|||
emit([ |
|||
"kind": "asr", |
|||
"id": (userInfo as? String) ?? "", |
|||
"text": result.data, |
|||
"final": status == 2 || status == 3, |
|||
"sid": result.sid, |
|||
]) |
|||
} |
|||
|
|||
public func onError(_ error: RTASRError, useInfo userInfo: Any?) { |
|||
emit([ |
|||
"kind": "error", |
|||
"where": "asr", |
|||
"id": (userInfo as? String) ?? "", |
|||
"code": error.code, |
|||
"message": error.errMsg, |
|||
"sid": error.sid, |
|||
]) |
|||
} |
|||
|
|||
public func its(_ its: ITS, on result: ITSResult, userInfo: Any) { |
|||
emit([ |
|||
"kind": "its", |
|||
"id": (userInfo as? String) ?? "", |
|||
"text": result.trans.dst, |
|||
"sid": result.sid, |
|||
]) |
|||
} |
|||
|
|||
public func its(_ its: ITS, onError error: ITSError, userInfo: Any) { |
|||
let id = (userInfo as? String) ?? "" |
|||
if transIndex + 1 < transOrder.count, let packed = pendingIts[id] { |
|||
transIndex += 1 |
|||
let parts = packed.split(separator: "|", maxSplits: 2).map(String.init) |
|||
if parts.count == 3 { |
|||
_ = runIts(id: id, from: parts[0], to: parts[1], text: parts[2]) |
|||
return |
|||
} |
|||
} |
|||
emit([ |
|||
"kind": "error", |
|||
"where": "its", |
|||
"id": id, |
|||
"code": error.code, |
|||
"message": error.errMsg, |
|||
"sid": error.sid, |
|||
]) |
|||
} |
|||
|
|||
public func tts(_ tts: TTS, on result: TTSResult, usrContext: Any) { |
|||
emit([ |
|||
"kind": "tts", |
|||
"id": (usrContext as? String) ?? "", |
|||
"pcm": FlutterStandardTypedData(bytes: result.data), |
|||
"final": result.status == 2, |
|||
"sid": result.sid, |
|||
]) |
|||
} |
|||
|
|||
public func tts(_ tts: TTS, onError error: TTSError, usrContext: Any) { |
|||
emit([ |
|||
"kind": "error", |
|||
"where": "tts", |
|||
"id": (usrContext as? String) ?? "", |
|||
"code": error.code, |
|||
"message": error.errMsg, |
|||
"sid": error.sid, |
|||
]) |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|||
<plist version="1.0"> |
|||
<dict> |
|||
<key>AvailableLibraries</key> |
|||
<array> |
|||
<dict> |
|||
<key>BinaryPath</key> |
|||
<string>SparkChain.framework/SparkChain</string> |
|||
<key>LibraryIdentifier</key> |
|||
<string>ios-arm64</string> |
|||
<key>LibraryPath</key> |
|||
<string>SparkChain.framework</string> |
|||
<key>SupportedArchitectures</key> |
|||
<array> |
|||
<string>arm64</string> |
|||
</array> |
|||
<key>SupportedPlatform</key> |
|||
<string>ios</string> |
|||
</dict> |
|||
</array> |
|||
<key>CFBundlePackageType</key> |
|||
<string>XFWK</string> |
|||
<key>XCFrameworkFormatVersion</key> |
|||
<string>1.0</string> |
|||
</dict> |
|||
</plist> |
|||
@ -0,0 +1,64 @@ |
|||
//
|
|||
// AIPPT.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 21.5.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
@class PPTResult; |
|||
@class PPTError; |
|||
@class AIPPT; |
|||
NS_ASSUME_NONNULL_BEGIN |
|||
@protocol PPTCallback <NSObject> |
|||
|
|||
- (void)ppt:(AIPPT *)ppt onResult:(PPTResult *)result userInfo:(id)userInfo; |
|||
|
|||
- (void)ppt:(AIPPT *)ppt onError:(PPTError *)error userInfo:(id)userInfo; |
|||
|
|||
@end |
|||
|
|||
@interface AIPPT : NSObject |
|||
|
|||
@property (nonatomic, weak) id<PPTCallback> callback; |
|||
|
|||
- (instancetype)init; |
|||
|
|||
- (void)createModel:(NSString *)createModel; |
|||
|
|||
- (void)theme:(NSString *)theme; |
|||
|
|||
- (void)businessId:(NSString *)businessId; |
|||
|
|||
- (void)author:(NSString *)author; |
|||
|
|||
- (void)isCardNote:(BOOL)isCardNote; |
|||
|
|||
- (int)asyncPPTFromText:(NSString *)text; |
|||
|
|||
- (int)asyncPPTFromText:(NSString *)text userInfo:(id _Nullable)userInfo; |
|||
|
|||
- (int)asyncPPTOutlineCreat:(NSString *)text; |
|||
|
|||
- (int)asyncPPTOutlineCreat:(NSString *)text userInfo:(id _Nullable)userInfo; |
|||
|
|||
- (int)asyncPPTFromSid:(NSString *)sid outline:(NSString * _Nullable)outline; |
|||
|
|||
- (int)asyncPPTFromSid:(NSString *)sid outline:(NSString * _Nullable)outline userInfo:(id _Nullable)userInfo; |
|||
|
|||
- (int)asyncPPTFromOutline:(NSString *)outline query:(NSString *)query; |
|||
|
|||
- (int)asyncPPTFromOutline:(NSString *)outline query:(NSString *)query userInfo:(id _Nullable)userInfo; |
|||
|
|||
- (int)asyncPPTGetTopicList; |
|||
|
|||
- (int)asyncPPTGetTopicListWithUserInfo:(id _Nullable)userInfo; |
|||
|
|||
- (int)asyncPPTGetResult:(NSString *)sid; |
|||
|
|||
- (int)asyncPPTGetResult:(NSString *)sid userInfo:(id _Nullable)userInfo; |
|||
|
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,83 @@ |
|||
//
|
|||
// ASR.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by XX on 2024/5/10.
|
|||
//
|
|||
|
|||
#ifndef ASR_h |
|||
#define ASR_h |
|||
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <SparkChain/SCEnums.h> |
|||
#import "AudioAttributes.h" |
|||
#import "ASRCallbacks.h" |
|||
#import "ASRHotwordsResult.h" |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ASR : NSObject |
|||
|
|||
@property (nonatomic, weak) id<ASRCallbacks> cbs; |
|||
|
|||
- (instancetype)init; |
|||
|
|||
- (instancetype)initWithRegion:(RegionType)region; |
|||
|
|||
- (instancetype)initWithLanguage:(NSString *)language domain:(NSString *)domain accent:(NSString *)accent; |
|||
|
|||
- (instancetype)initWithLanguage:(NSString *)language domain:(NSString *)domain accent:(NSString *)accent region:(RegionType)region; |
|||
|
|||
- (int)start:(AudioAttributes *)attributes; |
|||
- (int)start:(AudioAttributes *)attributes usrTag:(id)usrTag; |
|||
- (int)write:(NSData *)data; |
|||
- (int)stop:(BOOL)immediate; |
|||
|
|||
- (void)language:(NSString *)language; |
|||
- (void)domain:(NSString *)domain; |
|||
- (void)accent:(NSString *)accent; |
|||
- (void)vadEos:(int)vadEos; |
|||
- (void)dwa:(NSString *)dwa; |
|||
- (void)pd:(NSString *)pd; |
|||
- (void)ptt:(BOOL)enable; |
|||
- (void)rlang:(NSString *)rlang; |
|||
- (void)vinfo:(BOOL)vinfo; |
|||
- (void)nunum:(BOOL)enable; |
|||
- (void)speexSize:(int)speexSize; |
|||
- (void)nbest:(int)nbest; |
|||
- (void)wbest:(int)wbest; |
|||
- (void)vgap:(int)vgap; |
|||
- (void)proc:(BOOL)proc; |
|||
- (void)smth:(BOOL)smth; |
|||
- (void)ln:(NSString *)ln; |
|||
- (void)opt:(int)opt; |
|||
- (void)dhw:(NSString *)dhw; |
|||
- (void)ltc:(int)ltc; |
|||
|
|||
- (void)svad:(int)svad; |
|||
- (void)vadEnable:(BOOL)enable; |
|||
- (void)targetLanuage:(NSString *)target; |
|||
- (void)region:(RegionType)region; |
|||
|
|||
|
|||
- (void)addIntParam:(NSString *)key value:(int)value; |
|||
- (void)addBoolParam:(NSString *)key value:(BOOL)value; |
|||
- (void)addStringParam:(NSString *)key value:(NSString *)value; |
|||
|
|||
- (ASRHotwordsResult *)uploadHotwordsWithResId:(NSString *)resId |
|||
hotwordsFile:(NSString *)hotwordsFile |
|||
namexp:(NSString *)namexp |
|||
wordType:(NSString *)wordType; |
|||
- (ASRHotwordsResult *)uploadHotwordsWithResId:(NSString *)resId |
|||
hotwords:(NSData *)hotwords |
|||
namexp:(NSString *)namexp |
|||
wordType:(NSString *)wordType; |
|||
- (ASRHotwordsResult *)queryHotwordsWithResId:(NSString *)resId; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
|
|||
|
|||
#endif /* ASR_h */ |
|||
@ -0,0 +1,23 @@ |
|||
//
|
|||
// AsrCallbacks.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by XX on 2024/5/11.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import "ASRResult.h" |
|||
#import "ASRError.h" |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@protocol ASRCallbacks <NSObject> |
|||
|
|||
- (void)onResult:(ASRResult *)result usrTag:(id)usrTag; |
|||
|
|||
- (void)onError:(ASRError *)error usrTag:(id)usrTag; |
|||
|
|||
@end |
|||
|
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,25 @@ |
|||
//
|
|||
// ASRError.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by XX on 2024/5/11.
|
|||
//
|
|||
|
|||
#ifndef ASRError_h |
|||
#define ASRError_h |
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ASRError : NSObject |
|||
|
|||
@property (nonatomic, assign) int code; |
|||
@property (nonatomic, copy) NSString *errMsg; |
|||
@property (nonatomic, copy) NSString *sid; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
|
|||
#endif /* ASRError_h */ |
|||
@ -0,0 +1,22 @@ |
|||
//
|
|||
// ASRHotwordsResult.h
|
|||
// SparkChain
|
|||
//
|
|||
|
|||
#ifndef ASRHotwordsResult_h |
|||
#define ASRHotwordsResult_h |
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ASRHotwordsResult : NSObject |
|||
|
|||
@property (nonatomic, assign) int code; |
|||
@property (nonatomic, copy) NSString *response; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
|
|||
#endif /* ASRHotwordsResult_h */ |
|||
@ -0,0 +1,31 @@ |
|||
//
|
|||
// ASRResult.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by XX on 2024/5/11.
|
|||
//
|
|||
|
|||
#ifndef ASRResult_h |
|||
#define ASRResult_h |
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import "Transcription.h" |
|||
#import "Vad.h" |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ASRResult : NSObject |
|||
|
|||
@property (nonatomic, strong) NSArray<Transcription *> *transcriptions; |
|||
@property (nonatomic, strong) NSArray<Vad *> *vads; |
|||
@property (nonatomic) int begin; |
|||
@property (nonatomic) int end; |
|||
@property (nonatomic, copy) NSString *sid; |
|||
@property (nonatomic, copy) NSString *bestMatchText; |
|||
@property (nonatomic) int status; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
|
|||
#endif /* ASRResult_h */ |
|||
@ -0,0 +1,81 @@ |
|||
//
|
|||
// AST.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2025/11/14.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <SparkChain/SCEnums.h> |
|||
@class AST; |
|||
@class ASTResult; |
|||
@class ASTError; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
// 回调协议
|
|||
@protocol ASTDelegate <NSObject> |
|||
|
|||
- (void)ast:(AST *)ast onResult:(ASTResult *)result userInfo:(_Nullable id)userInfo; |
|||
|
|||
- (void)ast:(AST *)ast onError:(ASTError *)error userInfo:(_Nullable id)userInfo; |
|||
|
|||
@end |
|||
|
|||
@interface AST : NSObject |
|||
|
|||
@property (nonatomic, weak, readonly) id<ASTDelegate> delegate; |
|||
|
|||
- (instancetype)init NS_UNAVAILABLE; |
|||
|
|||
- (instancetype)initWithDelegate:(id<ASTDelegate>) delegate; |
|||
|
|||
- (instancetype)initWithregion:(RegionType)region delegate:(id<ASTDelegate>)delegate; |
|||
|
|||
- (int)start:(NSString *)lang audioEncoding:(NSString *)encoding sampleRate:(int)sampleRate userInfo:(_Nullable id)userInfo; |
|||
|
|||
- (int)write:(NSData *)data; |
|||
|
|||
- (int)stop:(BOOL)immediate; |
|||
|
|||
|
|||
#pragma mark - 热词管理 |
|||
|
|||
- (int)setHotwords:(NSString *)hotwords; |
|||
|
|||
- (int)uploadHotwords:(NSString *)hotwordsFile userInfo:(_Nullable id)userInfo; |
|||
|
|||
- (int)updateHotwords:(NSString *)hotwordsFile hotwordId:(int)hotwordId userInfo:(_Nullable id)userInfo; |
|||
|
|||
- (int)queryHotWords:(int)hotwordId userInfo:(_Nullable id)userInfo; |
|||
|
|||
#pragma mark - 翻译列表管理 |
|||
|
|||
- (int)setTransLists:(NSDictionary *)transLists; |
|||
|
|||
- (int)uploadTransLists:(NSString *)from to:(NSString *)to transLists:(NSDictionary *)transLists userInfo:(_Nullable id)userInfo; |
|||
|
|||
#pragma mark - 替换词管理 |
|||
- (int)setReplaceWords:(NSDictionary *)replaceWords; |
|||
|
|||
- (int)uploadReplaceList:(NSDictionary *)replaceList userInfo:(_Nullable id)userInfo; |
|||
|
|||
- (int)deleteReplaceList:(NSString *)replaceListId userInfo:(_Nullable id)userInfo; |
|||
|
|||
#pragma mark - 声纹管理 |
|||
- (int)registerVoicePrint:(NSData *)audioData audioType:(NSString *)audioType userInfo:(_Nullable id)userInfo; |
|||
|
|||
- (int)updateVoicePrint:(NSData *)audioData audioType:(NSString *)audioType featureId:(NSString *)featureId userInfo:(_Nullable id)userInfo; |
|||
|
|||
- (int)deleteVoicePrint:(NSArray *)featureIds userInfo:(_Nullable id)userInfo; |
|||
|
|||
#pragma mark - 参数设置 |
|||
- (void)addIntParam:(NSString *)key value:(int)value; |
|||
|
|||
- (void)addBoolParam:(NSString *)key value:(BOOL)value; |
|||
|
|||
- (void)addStringParam:(NSString *)key value:(NSString *)value; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,30 @@ |
|||
//
|
|||
// ASTError.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2025/11/19.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ASTError : NSObject |
|||
|
|||
@property (nonatomic, readonly) NSString *code; |
|||
|
|||
@property (nonatomic, readonly) NSString *sid; |
|||
|
|||
@property (nonatomic, readonly) NSString *fnType; |
|||
|
|||
@property (nonatomic, readonly) NSString *detail; |
|||
|
|||
@property (nonatomic, readonly) NSString *desc; |
|||
|
|||
@property (nonatomic, readonly) NSString *normal; |
|||
|
|||
@property (nonatomic, readonly) NSString *resType; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,80 @@ |
|||
//
|
|||
// ASTTransResult.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2025/11/14.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
// AST 声纹结果
|
|||
@interface ASTVoicePrintResult : NSObject |
|||
|
|||
@property (nonatomic, readonly) NSString *sid; |
|||
@property (nonatomic, readonly) NSString *featureId; |
|||
@property (nonatomic, readonly) NSInteger status; |
|||
@property (nonatomic, readonly) NSString *delFailIds; |
|||
|
|||
@end |
|||
|
|||
// AST TTS结果
|
|||
@interface ASTTtsResult : NSObject |
|||
|
|||
@property (nonatomic, readonly) NSInteger status; |
|||
@property (nonatomic, readonly) NSData * audio; |
|||
@property (nonatomic, readonly) NSString *engine; |
|||
@property (nonatomic, readonly) NSString *lang; |
|||
@property (nonatomic, readonly) NSString *rawResult; |
|||
|
|||
@end |
|||
|
|||
// AST 翻译结果
|
|||
@interface ASTTransResult : NSObject |
|||
|
|||
@property (nonatomic, readonly) NSString *src; |
|||
@property (nonatomic, readonly) NSString *dst; |
|||
@property (nonatomic, readonly) NSString *from; |
|||
@property (nonatomic, readonly) NSString *to; |
|||
@property (nonatomic, readonly) NSInteger type; |
|||
@property (nonatomic, readonly) BOOL end; |
|||
@property (nonatomic, readonly) NSString *isOver; |
|||
@property (nonatomic, readonly) NSString *isFinal; |
|||
@property (nonatomic, readonly) NSString *dstFixedPart; |
|||
|
|||
@end |
|||
|
|||
// AST热词结果
|
|||
@interface ASTHotwordsResult : NSObject |
|||
|
|||
@property (nonatomic, readonly) NSInteger hotWordId; |
|||
@property (nonatomic, readonly) NSString *hotWord; |
|||
@property (nonatomic, readonly) NSString *sid; |
|||
@property (nonatomic, readonly) NSString *engineUid; |
|||
@property (nonatomic, readonly) NSString *resId; |
|||
@property (nonatomic, readonly) NSString *lang; |
|||
|
|||
@end |
|||
|
|||
@interface ASTResult : NSObject |
|||
|
|||
@property (nonatomic, readonly) NSString *contextId; |
|||
@property (nonatomic, readonly) NSString *sessionId; |
|||
@property (nonatomic, readonly) NSString *resType; |
|||
@property (nonatomic, readonly) NSInteger status; |
|||
@property (nonatomic, readonly) NSInteger isEnd; |
|||
@property (nonatomic, readonly) NSString *data; |
|||
@property (nonatomic, readonly) NSString *rawResult; |
|||
|
|||
@property (nonatomic, readonly) ASTTransResult *transResult; |
|||
@property (nonatomic, readonly) ASTTtsResult *ttsResult; |
|||
@property (nonatomic, readonly) ASTHotwordsResult *hotwordsResult; |
|||
@property (nonatomic, readonly) ASTVoicePrintResult *voicePrintResult; |
|||
@property (nonatomic, readonly) NSString *transReplaceWordId; |
|||
@property (nonatomic, readonly) NSString *replaceListId; |
|||
@property (nonatomic, readonly) NSString *replaceListSid; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,29 @@ |
|||
//
|
|||
// AudioAttributes.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by XX on 2024/5/11.
|
|||
//
|
|||
|
|||
#ifndef AudioAttributes_h |
|||
#define AudioAttributes_h |
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface AudioAttributes : NSObject |
|||
|
|||
@property (nonatomic, assign) int sampleRate; |
|||
@property (nonatomic, copy) NSString *encoding; |
|||
@property (nonatomic, assign) int channels; |
|||
@property (nonatomic, assign) int bitdepth; |
|||
@property (nonatomic, assign) int frameSize; |
|||
|
|||
- (instancetype)init; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
|
|||
#endif /* AudioAttributes_h */ |
|||
@ -0,0 +1,20 @@ |
|||
//
|
|||
// Embedding.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 2024/11/28.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
@class EmbeddingOutput; |
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface Embedding : NSObject |
|||
|
|||
+ (EmbeddingOutput *)embedding:(NSString *)input domain:(NSString *)domain; |
|||
|
|||
+ (EmbeddingOutput *)embedding:(NSString *)input domain:(NSString *)domain uid:(NSString * __nullable)uid; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,34 @@ |
|||
//
|
|||
// EmbeddingOutput.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 2024/11/28.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface EmbeddingData : NSObject |
|||
|
|||
@property (readonly) float * byte NS_RETURNS_INNER_POINTER; |
|||
|
|||
@property (nonatomic, assign) NSUInteger length; |
|||
|
|||
@end |
|||
|
|||
@interface EmbeddingOutput : NSObject |
|||
|
|||
@property (nonatomic,copy,readonly) NSString * sid; |
|||
|
|||
@property (nonatomic,strong,readonly) EmbeddingData * data; |
|||
|
|||
@property (nonatomic,copy,readonly) NSString * raw; |
|||
|
|||
@property (nonatomic,copy,readonly) NSString * errMsg; |
|||
|
|||
@property (nonatomic,assign,readonly) int errCode; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,57 @@ |
|||
//
|
|||
// Feature.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
@class FeatureResult; |
|||
@class FeatureError; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@protocol FeatureCallback <NSObject> |
|||
|
|||
- (void)onResult:(FeatureResult *)result userInfo:(id _Nullable)userInfo; |
|||
- (void)onError:(FeatureError *)error userInfo:(id _Nullable)userInfo; |
|||
|
|||
@end |
|||
|
|||
@interface Feature : NSObject |
|||
|
|||
@property (nonatomic, weak) id<FeatureCallback> delegate; |
|||
|
|||
- (instancetype)init; |
|||
|
|||
/// 声纹注册
|
|||
/// - Parameters:
|
|||
/// - audioData: 音频数据
|
|||
/// - audioType: 音频类型
|
|||
/// - uid: 用户 id
|
|||
/// - userInfo: 用户自定义标识,可为 nil;非 nil 时会在回调中回传
|
|||
- (int)featureRegisterWithAudioData:(NSData *)audioData |
|||
audioType:(NSString *)audioType |
|||
uid:(NSString *)uid |
|||
userInfo:(id _Nullable)userInfo; |
|||
|
|||
/// 声纹更新
|
|||
/// - Parameters:
|
|||
/// - audioData: 音频数据
|
|||
/// - audioType: 音频类型
|
|||
/// - featureId: 声纹 id
|
|||
/// - userInfo: 用户自定义标识
|
|||
- (int)featureUpdateWithAudioData:(NSData *)audioData |
|||
audioType:(NSString *)audioType |
|||
featureId:(NSString *)featureId |
|||
userInfo:(id _Nullable)userInfo; |
|||
|
|||
/// 声纹删除(多个声纹 id 以逗号隔开)
|
|||
/// - Parameters:
|
|||
/// - featureIds: 声纹 id,多个以逗号分隔
|
|||
/// - userInfo: 用户自定义标识
|
|||
- (int)featureDeleteWithFeatureIds:(NSString *)featureIds |
|||
userInfo:(id _Nullable)userInfo; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,17 @@ |
|||
//
|
|||
// FeatureError.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface FeatureError : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString *code; |
|||
@property (nonatomic, copy, readonly) NSString *message; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,16 @@ |
|||
//
|
|||
// FeatureResult.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface FeatureResult : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString *featureId; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,112 @@ |
|||
//
|
|||
// IST.h
|
|||
// SparkChain_iOS
|
|||
// 极速语音转写
|
|||
// Created by pcfang on 2025/8/7.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
@class IST; |
|||
@class ISTResult; |
|||
@class ISTError; |
|||
|
|||
@protocol ISTDelegate <NSObject> |
|||
@optional |
|||
- (void)ist:(IST *)ist onResult:(ISTResult *)result userInfo:(id)userInfo; |
|||
|
|||
- (void)ist:(IST *)ist onProcess:(NSString *)process userInfo:(id)userInfo; |
|||
|
|||
- (void)ist:(IST *)ist onError:(ISTError *)error userInfo:(id)userInfo; |
|||
|
|||
@end |
|||
|
|||
@interface IST : NSObject |
|||
|
|||
@property (nonatomic, copy) NSString * requestId; |
|||
|
|||
@property (nonatomic, copy) NSString * language; |
|||
|
|||
@property (nonatomic, copy) NSString * domain; |
|||
|
|||
@property (nonatomic, copy) NSString * accent; |
|||
|
|||
@property (nonatomic, copy) NSString * callbackUrl; |
|||
|
|||
@property (nonatomic, assign) int vsppOn; |
|||
|
|||
@property (nonatomic, assign) int speakerNum; |
|||
|
|||
@property (nonatomic, assign) int outputType; |
|||
|
|||
@property (nonatomic, assign) int postprocON; |
|||
|
|||
@property (nonatomic, copy) NSString * pd; |
|||
|
|||
@property (nonatomic, assign) int duration; |
|||
|
|||
@property (nonatomic, assign) int enableSubtitle; |
|||
|
|||
@property (nonatomic, assign) BOOL smoothproc; |
|||
|
|||
@property (nonatomic, assign) BOOL colloqproc; |
|||
|
|||
@property (nonatomic, assign) BOOL languageType; |
|||
|
|||
@property (nonatomic, assign) int vto; |
|||
|
|||
@property (nonatomic, copy) NSString * dhw; |
|||
|
|||
@property (nonatomic, weak) id<ISTDelegate> delegate; |
|||
|
|||
- (void)addIntParam:(NSString *)key value:(int)value; |
|||
- (void)addBoolParam:(NSString *)key value:(BOOL)value; |
|||
- (void)addStringParam:(NSString *)key value:(NSString *)value; |
|||
|
|||
|
|||
- (instancetype)initDelegate:(id<ISTDelegate>) delegate; |
|||
|
|||
|
|||
/// 上传音频文件,返回0成功,其他失败
|
|||
/// - Parameters:
|
|||
/// - audioPath: 音频文件路径
|
|||
/// - requestId: 请求ID
|
|||
/// - userInfo: 用户自定义数据
|
|||
- (int)upload:(NSString *) audioPath requestId:(NSString *)requestId userInfo:(__nullable id)userInfo; |
|||
|
|||
/// 分片上传音频文件,0表示成功,其他表示失败
|
|||
/// - Parameters:
|
|||
/// - audioPath: 音频文件路径
|
|||
/// - requestId: 请求ID
|
|||
/// - partSize: 分片大小
|
|||
/// - userInfo: 用户自定义数据
|
|||
- (int)mpUpload:(NSString *)audioPath |
|||
requestId:(NSString *)requestId |
|||
partSize:(NSUInteger)partSize |
|||
userInfo:(__nullable id)userInfo; |
|||
|
|||
/// 创建任务,0表示成功,其他表示失败
|
|||
/// - Parameters:
|
|||
/// - requestId: 请求ID
|
|||
/// - path: 音频文件URL
|
|||
/// - format: 音频的采样率支持16k,audio/L16;rate=16000
|
|||
/// - encoding: 音频数据格式:wav、pcm(传参raw),mp3(传参lame)
|
|||
/// - userInfo: 用户自定义数据
|
|||
- (int)createTask:(NSString *)requestId |
|||
audioURLPath:(NSString *)path |
|||
format:(NSString *)format |
|||
encoding:(NSString *)encoding |
|||
userInfo:(__nullable id)userInfo; |
|||
|
|||
/// 查询任务,0表示成功,其他表示失败
|
|||
/// - Parameters:
|
|||
/// - taskId: 任务ID
|
|||
/// - userInfo: 用户自定义数据
|
|||
- (int)queryTask:(NSString *)taskId userInfo:(__nullable id)userInfo; |
|||
|
|||
/// 停止识别
|
|||
- (int)stop; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,22 @@ |
|||
//
|
|||
// ISTError.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2025/8/7.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ISTError : NSObject |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property(nonatomic, assign, readonly) int code; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * errMsg; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,34 @@ |
|||
//
|
|||
// ISTResult.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2025/8/7.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ISTResult : NSObject |
|||
|
|||
@property (nonatomic, assign, readonly) int code; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * key; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * url; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * taskId; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * taskStatus; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * taskType; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * result; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * rawResult; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,53 @@ |
|||
//
|
|||
// ITS.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 15.5.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
@class ITS; |
|||
@class ITSResult; |
|||
@class ITSError; |
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
typedef enum { |
|||
ITRANS = 0, //讯飞翻译
|
|||
NIUTRANS, //小牛翻译
|
|||
ITRANS_SG, //讯飞翻译(新加坡)
|
|||
GOOGLETRANS //谷歌翻译
|
|||
} TransType; |
|||
|
|||
@protocol ITSCallbacks <NSObject> |
|||
|
|||
- (void)its:(ITS *)its onResult:(ITSResult *)result userInfo:(id)userInfo; |
|||
|
|||
- (void)its:(ITS *)its onError:(ITSError *)error userInfo:(id)userInfo; |
|||
|
|||
@end |
|||
|
|||
@interface ITS : NSObject |
|||
|
|||
- (instancetype) init; |
|||
|
|||
- (instancetype) initWithType:(TransType)type; |
|||
|
|||
- (instancetype) initWithFormLanguage:(NSString *)from toLanguage:(NSString *)to; |
|||
|
|||
- (instancetype)initWithFormLanguage:(NSString *)from toLanguage:(NSString *)to type:(TransType)type; |
|||
|
|||
@property (nonatomic, weak) id<ITSCallbacks> callbacks; |
|||
|
|||
@property (nonatomic, copy) NSString * fromLanguage; |
|||
|
|||
@property (nonatomic, copy) NSString * toLanguage; |
|||
|
|||
@property (nonatomic, copy) NSString * resId; |
|||
|
|||
- (int)arun:(NSString *)text; |
|||
|
|||
- (int)arun:(NSString *)text userInfo:(_Nullable id)userInfo; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,22 @@ |
|||
//
|
|||
// ITSError.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 15.5.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ITSError : NSObject |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property(nonatomic, assign, readonly) int code; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * errMsg; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,34 @@ |
|||
//
|
|||
// ITSResult.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 15.5.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface Trans : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * src; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * dst; |
|||
|
|||
@end |
|||
|
|||
@interface ITSResult : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property (nonatomic, assign, readonly) int status; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * from; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * to; |
|||
|
|||
@property (nonatomic, strong, readonly) Trans * trans; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,40 @@ |
|||
//
|
|||
// ImageTrans.h
|
|||
// IMAGE_TRANS
|
|||
//
|
|||
// Created by xyzhang on 2024/5/28.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
@class ImageTrans; |
|||
@class ImageTransResult; |
|||
@class ImageTransError; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@protocol ImageTransDelegate <NSObject> |
|||
|
|||
- (void)imgTrans:(ImageTrans *)imgTrans onResult:(ImageTransResult *)result usrContext:(id)usrContext; |
|||
|
|||
- (void)imgTrans:(ImageTrans *)imgTrans onError:(ImageTransError *)error usrContext:(id)usrContext; |
|||
|
|||
@end |
|||
|
|||
@interface ImageTrans : NSObject |
|||
|
|||
@property (nonatomic, weak) id<ImageTransDelegate> delegate; |
|||
//@property (nonatomic, copy) NSString *imagePath;
|
|||
@property (nonatomic, copy) NSString *ocrLanguage; |
|||
@property (nonatomic, copy) NSString *fromLanguage; |
|||
@property (nonatomic, copy) NSString *toLanguage; |
|||
@property (nonatomic, assign) int returnType; // ???
|
|||
|
|||
- (instancetype)init; |
|||
- (instancetype)initWithOcrLanguage:(NSString *)ocrLanguage fromLanguage:(NSString *)fromLanguage toLanguage:(NSString *)toLanguage returnType:(int)returnType; |
|||
|
|||
- (int)arun:(NSData *)imageData encoding:(NSString *)encoding userInfo:(id)userInfo; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,20 @@ |
|||
//
|
|||
// ImageTransError.h
|
|||
// IMAGE_TRANS
|
|||
//
|
|||
// Created by xyzhang on 2024/5/28.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface ImageTransError : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString *sid; |
|||
@property (nonatomic, copy, readonly) NSString *errMsg; |
|||
@property (nonatomic, assign, readonly) int code; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,32 @@ |
|||
//
|
|||
// ImageTransResult.h
|
|||
// IMAGE_TRANS
|
|||
//
|
|||
// Created by xyzhang on 2024/5/28.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface BlockText : NSObject |
|||
|
|||
@property (nonatomic, copy) NSString *srcText; |
|||
@property (nonatomic, copy) NSString *dstText; |
|||
|
|||
@end |
|||
|
|||
@interface ImageTransResult : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString *sid; |
|||
//@property (nonatomic, copy, readonly) NSString *itsImage;
|
|||
//@property (nonatomic, copy, readonly) NSString *itsOutput;
|
|||
@property (nonatomic, copy, readonly) NSData *itsImageData; //图片翻译 二进制数据
|
|||
@property (nonatomic, copy, readonly) NSString *itsOutputJsStr; // 整体
|
|||
|
|||
@property (nonatomic, assign, readonly) int status; |
|||
@property (nonatomic, copy, readonly) NSArray <BlockText *>*blockTexts; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,168 @@ |
|||
//
|
|||
// LLM.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 12.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
@class LLM; |
|||
@class LLMEvent; |
|||
@class LLMError; |
|||
@class LLMResult; |
|||
@class LLMConfig; |
|||
@class LLMOutput; |
|||
@class LLMTools; |
|||
@class Memory; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
typedef enum{ |
|||
TEXT_GENERATION = 0, |
|||
IMAGE_GENERATION, |
|||
IMAGE_UNDERSTANDING |
|||
} ModelType; |
|||
|
|||
@protocol LLMCallback <NSObject> |
|||
|
|||
- (void)llm:(LLM *)llm onResult:(LLMResult * _Nullable)result usrContext:(id _Nullable)usrContext; |
|||
|
|||
- (void)llm:(LLM *)llm onEvent:(LLMEvent * _Nullable)event usrContext:(id _Nullable)usrContext; |
|||
|
|||
- (void)llm:(LLM *)llm onError:(LLMError * _Nullable)error usrContext:(id _Nullable)usrContext; |
|||
|
|||
@end |
|||
|
|||
|
|||
@interface LLM : NSObject |
|||
|
|||
@property(nonatomic, weak) id<LLMCallback> callback; |
|||
|
|||
@property(nonatomic, strong, readonly) LLMConfig * config; |
|||
|
|||
#pragma mark - init |
|||
- (instancetype)init; |
|||
|
|||
- (instancetype)initWithConfig:(LLMConfig * _Nullable)config; |
|||
|
|||
- (instancetype)initWithCallback:(id<LLMCallback> _Nullable)callback; |
|||
|
|||
- (instancetype)initWithConfig:(LLMConfig * _Nullable)config callback:(id<LLMCallback> _Nullable)callback; |
|||
|
|||
- (instancetype)initWithModelType:(ModelType)modelType config:(LLMConfig *)config; |
|||
|
|||
- (instancetype)initWithModelType:(ModelType)modelType config:(LLMConfig * _Nullable)config memory:(Memory * _Nullable)memory; |
|||
|
|||
#pragma mark - 同步接口 |
|||
/// 同步获取LLM结果
|
|||
/// - Parameter query: 用户问题
|
|||
- (LLMOutput *)run:(NSString *)query; |
|||
|
|||
- (LLMOutput *)run:(NSString *)query image:(NSData *)image; |
|||
|
|||
/// 同步获取LLM结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - ttl: 超时时间
|
|||
- (LLMOutput *)run:(NSString *)query ttl:(int)ttl; |
|||
|
|||
/// 同步获取LLM结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - tools: 工具(如function call)
|
|||
- (LLMOutput *)run:(NSString *)query tools:(LLMTools *)tools; |
|||
|
|||
/// 同步获取LLM结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - tools: 工具(如function call)
|
|||
/// - ttl: 超时时间
|
|||
- (LLMOutput *)run:(NSString *)query tools:(LLMTools *)tools ttl:(int)ttl; |
|||
|
|||
/// 同步获取图片理解结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - image: 图片
|
|||
- (LLMOutput *)run:(NSString *)query image:(NSData *)image; |
|||
|
|||
/// 使用raw json同步调用大模型
|
|||
/// - Parameters:
|
|||
/// - json: 原始JSON
|
|||
/// - ttl: 超时时间
|
|||
- (LLMOutput *)runWithJSON:(NSString *)json ttl:(int)ttl; |
|||
|
|||
#pragma mark - 异步接口 |
|||
/// 异步获取LLM结果
|
|||
/// - Parameter query: 用户问题
|
|||
- (int)arun:(NSString *)query; |
|||
|
|||
/// 异步获取LLM结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - usrContext: 用户自定义数据
|
|||
- (int)arun:(NSString *)query usrContext:(id _Nullable)usrContext; |
|||
|
|||
- (int)arun:(NSString *)query image:(NSData *)image usrContext:(id _Nullable)usrContext; |
|||
|
|||
/// 异步获取LLM结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - tools: 工具(如function call)
|
|||
- (int)arun:(NSString *)query tools:(LLMTools *)tools; |
|||
|
|||
/// 异步获取LLM结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - tools: 工具(如function call)
|
|||
/// - usrContext: 用户自定义数据
|
|||
- (int)arun:(NSString *)query tools:(LLMTools *)tools usrContext:(id _Nullable)usrContext; |
|||
|
|||
/// 异步获取图片理解结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - image: 图片
|
|||
- (int)arun:(NSString *)query image:(NSData *)image; |
|||
|
|||
/// 异步获取图片理解结果
|
|||
/// - Parameters:
|
|||
/// - query: 用户问题
|
|||
/// - image: 图片
|
|||
/// - usrContext: 用户自定义数据
|
|||
- (int)arun:(NSString *)query image:(NSData *)image usrContext:(id _Nullable)usrContext; |
|||
|
|||
/// 使用raw json异步调用大模型
|
|||
/// - Parameters:
|
|||
/// - json: 原始JSON
|
|||
/// - usrContext: 用户自定义数据
|
|||
- (int)arunWithJSON:(NSString *)json usrContext:(id _Nullable)usrContext; |
|||
|
|||
#pragma mark - 其他 |
|||
/// 添加system角色(如:你是一个智能旅游助手,推荐旅游地点)
|
|||
/// - Parameter prompt: system内容
|
|||
- (int)addSystemPrompt:(NSString *)prompt; |
|||
|
|||
/// 清除上下文
|
|||
- (void)clearHistory; |
|||
|
|||
/// 停止输出
|
|||
- (int)stop; |
|||
|
|||
@end |
|||
|
|||
|
|||
@interface LLMFactory : NSObject |
|||
|
|||
+ (LLM *)textGeneration:(LLMConfig * _Nullable)config; |
|||
|
|||
+ (LLM *)textGeneration:(LLMConfig * _Nullable)config memory:(Memory * _Nullable)memory; |
|||
|
|||
+ (LLM *)imageGeneration:(LLMConfig * _Nullable)config; |
|||
|
|||
+ (LLM *)imageGeneration:(LLMConfig * _Nullable)config width:(int)width height:(int)height; |
|||
|
|||
+ (LLM *)imageUnderstanding:(LLMConfig * _Nullable)config; |
|||
|
|||
+ (LLM *)imageUnderstanding:(LLMConfig * _Nullable)config memory:(Memory * _Nullable)memory; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,20 @@ |
|||
//
|
|||
// LLMBaseOutput.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 15.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface LLMBaseOutput : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
|
|||
- (instancetype)initWithSid:(NSString *)sid; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,46 @@ |
|||
//
|
|||
// LLMConfig.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 12.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
#define chainProperty(returnType,name) property(nonatomic, readonly, copy) returnType (^name) |
|||
|
|||
@interface LLMConfig : NSObject |
|||
|
|||
@chainProperty(LLMConfig *,uid)(NSString * uid); |
|||
|
|||
@chainProperty(LLMConfig *,domain)(NSString * domain); |
|||
|
|||
@chainProperty(LLMConfig *,auditing)(NSString * auditing); |
|||
|
|||
@chainProperty(LLMConfig *,chatID)(NSString * chatID); |
|||
|
|||
@chainProperty(LLMConfig *,temperature)(float temperature); |
|||
|
|||
@chainProperty(LLMConfig *,topK)(int topK); |
|||
|
|||
@chainProperty(LLMConfig *,maxToken)(int maxToken); |
|||
|
|||
@chainProperty(LLMConfig *,url)(NSString * url); |
|||
|
|||
@chainProperty(LLMConfig *,showRefLabel)(BOOL isShow); |
|||
|
|||
@chainProperty(LLMConfig *,tools)(NSString * toolList); |
|||
|
|||
@chainProperty(LLMConfig *,addString)(NSString * key, NSString * param); |
|||
|
|||
@chainProperty(LLMConfig *,addDouble)(NSString * key,double param); |
|||
|
|||
@chainProperty(LLMConfig *,addInt)(NSString * key,int param); |
|||
|
|||
@chainProperty(LLMConfig *,addBool)(NSString * key,BOOL param); |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,21 @@ |
|||
//
|
|||
// LLMError.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 12.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <SparkChain/LLMBaseOutput.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface LLMError : LLMBaseOutput |
|||
|
|||
@property (nonatomic, assign, readonly) int errCode; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * errMsg; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,21 @@ |
|||
//
|
|||
// LLMEvent.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 12.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <SparkChain/LLMBaseOutput.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface LLMEvent : LLMBaseOutput |
|||
|
|||
@property (nonatomic, assign, readonly) int eventID; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * eventMsg; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,65 @@ |
|||
//
|
|||
// LLMResult.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 12.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <SparkChain/LLMBaseOutput.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface LLMResult : LLMBaseOutput |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable raw; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable role; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable content; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable reasoningContent; |
|||
|
|||
@property (nonatomic, copy, readonly) NSData * _Nullable image; |
|||
|
|||
@property (nonatomic, assign, readonly) int status; |
|||
|
|||
@property (nonatomic, assign, readonly) int completionTokens; |
|||
|
|||
@property (nonatomic, assign, readonly) int promptTokens; |
|||
|
|||
@property (nonatomic, assign, readonly) int totalTokens; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * functionCall; |
|||
@end |
|||
|
|||
|
|||
@interface LLMOutput : LLMBaseOutput |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable raw; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable role; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable content; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable reasoningContent; |
|||
|
|||
@property (nonatomic, copy, readonly) NSData * _Nullable image; |
|||
|
|||
@property (nonatomic, assign, readonly) int status; |
|||
|
|||
@property (nonatomic, assign, readonly) int completionTokens; |
|||
|
|||
@property (nonatomic, assign, readonly) int promptTokens; |
|||
|
|||
@property (nonatomic, assign, readonly) int totalTokens; |
|||
|
|||
@property (nonatomic, assign, readonly) int errCode; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * _Nullable errMsg; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * functionCall; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,22 @@ |
|||
//
|
|||
// LLMTools.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 2024/11/21.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface LLMTools : NSObject |
|||
|
|||
@property(nonatomic, copy) NSString * toolType; |
|||
|
|||
@property(nonatomic, copy) NSString * toolDescription; |
|||
|
|||
- (instancetype)initWithType:(NSString *)type description:(NSString *)description; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,28 @@ |
|||
//
|
|||
// Memory.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 2024/11/22.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface Memory : NSObject |
|||
|
|||
- (instancetype) init NS_UNAVAILABLE; |
|||
|
|||
/// 按照轮数进行大模型交互上下文记忆,默认5轮,超出轮数自动移除最早的会话
|
|||
+ (instancetype)windowMemory; |
|||
/// 按照轮数进行大模型交互上下文记忆,用户自定义轮数,超出轮数自动移除最早的会话
|
|||
+ (instancetype)windowMemory:(int)maxCache; |
|||
|
|||
/// 按照token进行大模型交互上下文记忆,默认4096
|
|||
+ (instancetype)tokenMemory; |
|||
/// 按照token进行大模型交互上下文记忆,用户自定义token
|
|||
+ (instancetype)tokenMemory:(int)maxToken; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,37 @@ |
|||
//
|
|||
// OCR.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 16.5.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
@class OCR; |
|||
@class OCRResult; |
|||
@class OCRError; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@protocol OCRCallbacks <NSObject> |
|||
|
|||
- (void)ocr:(OCR *)ocr onResult:(OCRResult *)result userInfo:(id)userInfo; |
|||
|
|||
- (void)ocr:(OCR *)ocr onError:(OCRError *)error userInfo:(id)userInfo; |
|||
|
|||
@end |
|||
|
|||
@interface OCR : NSObject |
|||
|
|||
@property (nonatomic, weak) id <OCRCallbacks> callbacks; |
|||
|
|||
- (int)arunWithImagePath:(NSString *)imagePath; |
|||
|
|||
- (int)arunWithImagePath:(NSString *)imagePath userInfo:(id)userInfo; |
|||
|
|||
- (int)arunWithImageData:(NSData *)imageData; |
|||
|
|||
- (int)arunWithImageData:(NSData *)imageData userInfo:(id)userInfo; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,22 @@ |
|||
//
|
|||
// OCRError.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 17.5.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface OCRError : NSObject |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property(nonatomic, assign, readonly) int code; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * errMsg; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,27 @@ |
|||
//
|
|||
// OCRExtension.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 17.5.24.
|
|||
//
|
|||
|
|||
#import "OCRResult.h" |
|||
#import "OCRError.h" |
|||
#include <sparkchain_api/sc_ocr.h> |
|||
|
|||
@interface OCRLine () |
|||
- (instancetype)initWithLine:(SparkChain::Line *)line; |
|||
@end |
|||
|
|||
@interface OCRResult () |
|||
|
|||
- (instancetype)initWithResult:(SparkChain::OCRResult *)result; |
|||
|
|||
@end |
|||
|
|||
|
|||
@interface OCRError () |
|||
|
|||
- (instancetype)initWithError:(SparkChain::OCRError *)error; |
|||
|
|||
@end |
|||
@ -0,0 +1,52 @@ |
|||
//
|
|||
// OCRResult.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 17.5.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface OCRLine : NSObject |
|||
/// 文本块被旋转的角度
|
|||
@property (nonatomic, assign, readonly) int angle; |
|||
///字符中心坐标,Int类型
|
|||
@property (nonatomic, copy, readonly) NSArray <NSArray <NSNumber *> *> * charCenters; |
|||
/// 字符块坐标(每个字符左上角起,顺时针一周四角坐标形成的集合), int类型
|
|||
@property (nonatomic, copy, readonly) NSArray <NSArray <NSNumber *> *> * charPolygons; |
|||
/// 字符置信度,值域范围:0-1,double类型
|
|||
@property (nonatomic, copy, readonly) NSArray <NSNumber *> * charScore; |
|||
/// 文本块坐标(文本阅读方向的左上角起,顺时针一周四角坐标形成的集合),int类型
|
|||
@property (nonatomic, copy, readonly) NSArray <NSNumber *> * position; |
|||
/// 文本块所属属性表下标,从0开始
|
|||
@property (nonatomic, assign, readonly) int property; |
|||
/// 文本块的整体置信度
|
|||
@property (nonatomic, assign, readonly) double score; |
|||
/// 文本块内容
|
|||
@property (nonatomic, copy, readonly) NSString * text; |
|||
@end |
|||
|
|||
@interface OCRResult : NSObject |
|||
/// 请求的sid
|
|||
@property (nonatomic, copy, readonly) NSString * sid; |
|||
/// 返回结果的状态 (0:首结果,1:中间结果,2:尾结果, 3:一次性结果)
|
|||
@property (nonatomic, assign, readonly) int status; |
|||
/// 图片旋转角度
|
|||
@property (nonatomic, assign, readonly) int imageAngle; |
|||
/// 文本块识别信息集合
|
|||
@property (nonatomic, copy, readonly) NSArray <OCRLine *> * lines; |
|||
/// 文本块属性表,可选值:text(文本)、stamp(印章)、formula(公示);
|
|||
/// 与lines里的每个元素的property搭配使用,
|
|||
/// property:0文本、1印章、2公式
|
|||
@property (nonatomic, copy, readonly) NSArray <NSString *> * properties; |
|||
/// 旋转后图片宽度
|
|||
@property (nonatomic, assign, readonly) int rotatedImageWidth; |
|||
/// 旋转后图片高度
|
|||
@property (nonatomic, assign, readonly) int rotatedImageHeight; |
|||
/// 全文识别的所有内容(同行内容整合为一行输出)
|
|||
@property (nonatomic, copy, readonly) NSString * wholeText; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,28 @@ |
|||
//
|
|||
// OnlineTTS.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by XX on 2024/5/10.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <SparkChain/SCEnums.h> |
|||
#import "TTS.h" |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface OnlineTTS : TTS |
|||
|
|||
@property (nonatomic, copy) NSString *aue; |
|||
@property (nonatomic, assign) int sfl; |
|||
@property (nonatomic, copy) NSString *auf; |
|||
@property (nonatomic, copy) NSString *tte; |
|||
|
|||
- (instancetype)initWithVcn:(NSString *)vcn; |
|||
|
|||
/// 指定接入区域与发音人(与底层 `OnlineTTS(REGION_TYPE, string)` 一致)。
|
|||
- (instancetype)initWithRegion:(RegionType)region vcn:(NSString *)vcn; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,22 @@ |
|||
//
|
|||
// PPTError.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 2025/5/14.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface PPTError : NSObject |
|||
|
|||
@property (nonatomic, assign) int code; |
|||
|
|||
@property (nonatomic, copy) NSString *errMsg; |
|||
|
|||
@property (nonatomic, copy) NSString *sid; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,52 @@ |
|||
//
|
|||
// PPTInfo.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by pcfang on 22.5.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface PPTTheme : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * key; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * name; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * thumbnail; |
|||
|
|||
@end |
|||
|
|||
@interface PPTInfo : NSObject |
|||
|
|||
@property (nonatomic, assign, readonly) int code; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * coverImgSrc; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * title; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * subtitle; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * pptUrl; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * pptId; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * outline; |
|||
|
|||
@property (nonatomic, strong, readonly) NSArray <PPTTheme *> * themes; |
|||
|
|||
@end |
|||
|
|||
@interface PPTResult : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property (nonatomic, strong, readonly) PPTInfo * info; |
|||
|
|||
@property (nonatomic, assign, readonly) int progress; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,25 @@ |
|||
//
|
|||
// PersonateTTS.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 23.2.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import "TTS.h" |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface PersonateTTS : TTS |
|||
@property(nonatomic, assign) int topK; |
|||
|
|||
@property(nonatomic, assign) int maxTokens; |
|||
|
|||
@property(nonatomic, copy) NSString * oralLevel; |
|||
|
|||
@property(nonatomic, assign) bool sparkAssist; |
|||
|
|||
- (instancetype)initWithVcn:(NSString *)vcn; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,176 @@ |
|||
//
|
|||
// RAASR.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2024/8/8.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <SparkChain/SCEnums.h> |
|||
@class RAASRResult; |
|||
@class RAASRError; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@protocol RAASRCallback <NSObject> |
|||
|
|||
- (void)onResult:(RAASRResult *)result userInfo:(id _Nullable)userInfo; |
|||
|
|||
- (void)onError:(RAASRError *)error userInfo:(id _Nullable)userInfo; |
|||
|
|||
- (void)onProcess:(double)dltotal dlnow:(double)dlnow utotal:(double)utotal ulnow:(double)ulnow userInfo:(id _Nullable)userInfo; |
|||
|
|||
@end |
|||
|
|||
@interface RAASR : NSObject |
|||
|
|||
//common
|
|||
@property (nonatomic, copy) NSString * pd; |
|||
|
|||
@property (nonatomic, copy) NSString * audioURL; |
|||
|
|||
@property (nonatomic, assign) int languageType; |
|||
|
|||
@property (nonatomic, assign) int engSegMax; |
|||
|
|||
@property (nonatomic, assign) int engSegMin; |
|||
|
|||
@property (nonatomic, assign) float engSegWeight; |
|||
|
|||
@property (nonatomic, assign) bool engSmoothproc; |
|||
|
|||
@property (nonatomic, assign) bool engColloqproc; |
|||
|
|||
@property (nonatomic, assign) int engVadMdn; |
|||
|
|||
@property (nonatomic, assign) int engVadMargin; |
|||
|
|||
@property (nonatomic, assign) int engRlang; |
|||
|
|||
//国内
|
|||
@property (nonatomic, copy) NSString * language; |
|||
|
|||
@property (nonatomic, copy) NSString * resultType; |
|||
|
|||
@property (nonatomic, copy) NSString * hotWord; |
|||
|
|||
@property (nonatomic, assign) int candidate; |
|||
|
|||
@property (nonatomic, assign) int roleType; |
|||
|
|||
@property (nonatomic, assign) int roleNum; |
|||
|
|||
@property (nonatomic, copy) NSString * audioMode; |
|||
|
|||
@property (nonatomic, assign) int standardWav; |
|||
|
|||
@property (nonatomic, assign) int trackMode; |
|||
|
|||
@property (nonatomic, copy) NSString * transLanguage; |
|||
|
|||
@property (nonatomic, assign) int transMode; |
|||
|
|||
//海外
|
|||
// common params
|
|||
@property (nonatomic, copy) NSString * ostUid; |
|||
@property (nonatomic, copy) NSString * ostDeviceId; |
|||
//@property (nonatomic, copy) NSString * ostRequestId;
|
|||
@property (nonatomic, copy) NSString * ostDeviceImei; |
|||
@property (nonatomic, copy) NSString * ostDeviceImsi; |
|||
@property (nonatomic, copy) NSString * ostDeviceMac; |
|||
@property (nonatomic, copy) NSString * ostDeviceOther; |
|||
@property (nonatomic, copy) NSString * ostNetType; |
|||
@property (nonatomic, copy) NSString * ostNetIsp; |
|||
@property (nonatomic, copy) NSString * ostAppVer; |
|||
|
|||
// business params
|
|||
@property (nonatomic, copy) NSString * ostTaskType; |
|||
@property (nonatomic, copy) NSString * ostFormat; |
|||
@property (nonatomic, copy) NSString * ostEncoding; |
|||
@property (nonatomic, assign) int ostAudioSize; |
|||
@property (nonatomic, copy) NSString * ostAudioSrc; |
|||
@property (nonatomic, copy) NSString * ostCallbackKey; |
|||
@property (nonatomic, copy) NSString * ostCallbackSecret; |
|||
@property (nonatomic, copy) NSArray<NSString *> * ostFeatureList; |
|||
@property (nonatomic, assign) int ostProcinfoOn; |
|||
@property (nonatomic, assign) int ostVsppOn; |
|||
@property (nonatomic, assign) int ostSpeakerNum; |
|||
@property (nonatomic, assign) int ostOutputType; |
|||
@property (nonatomic, assign) int ostPostprocOn; |
|||
@property (nonatomic, assign) int ostResegment; |
|||
@property (nonatomic, copy) NSString * ostResId; |
|||
@property (nonatomic, assign) int ostDuration; |
|||
@property (nonatomic, copy) NSString * ostResUrl; |
|||
@property (nonatomic, assign) int ostEnableSubtitle; |
|||
@property (nonatomic, assign) int ostVto; |
|||
@property (nonatomic, copy) NSString * ostDhw; |
|||
@property (nonatomic, assign) int ostNbest; |
|||
@property (nonatomic, assign) int ostCombineMax; |
|||
@property (nonatomic, assign) int ostNunum; |
|||
|
|||
|
|||
- (void)addIntParam:(NSString *)key value:(int)value; |
|||
- (void)addBoolParam:(NSString *)key value:(BOOL)value; |
|||
- (void)addStringParam:(NSString *)key value:(NSString *)value; |
|||
|
|||
@property (nonatomic, weak) id<RAASRCallback> delegate; |
|||
|
|||
- (instancetype)init; |
|||
|
|||
- (instancetype)initWithRegion:(RegionType)regoin; |
|||
|
|||
- (instancetype)initWithSecretKey:(NSString *)apiKey; |
|||
|
|||
- (instancetype)initWithSecretKey:(NSString *)apiKey regoin:(RegionType)regoin; |
|||
|
|||
- (void)setOstPersonalizationKey:(NSString *)key value:(NSString *)value; |
|||
|
|||
/// 上传音频文件
|
|||
/// - Parameters:
|
|||
/// - fileName: 音频文件路径(仅国内支持),或者音频链接,国内需设置audioMode为urlLink
|
|||
/// - requestId: 仅海外支持,表示请求id,必传;国内可传空值
|
|||
/// - userInfo: 用户自定义标识
|
|||
- (int)uploadAsync:(NSString *)fileName requestId:(NSString *)requestId userInfo:(id _Nullable)userInfo; |
|||
|
|||
/// 上传音频文件
|
|||
/// - Parameter fileName: 音频文件路径(仅国内支持),或者音频链接,国内需设置audioMode为urlLink
|
|||
- (int) uploadAsync:(NSString *)fileName; |
|||
|
|||
/// 查询订单状态
|
|||
/// - Parameters:
|
|||
/// - orderId: 订单id
|
|||
/// - userInfo: 用户自定义标识
|
|||
- (int)queryResult:(NSString *)orderId userInfo:(id _Nullable)userInfo; |
|||
|
|||
/// 查询订单状态
|
|||
/// - Parameter orderId: 订单id
|
|||
- (int)queryResult:(NSString *)orderId; |
|||
|
|||
//仅国内
|
|||
- (int)stop; |
|||
|
|||
#pragma mark - overseas |
|||
//海外
|
|||
|
|||
/// 取消任务,仅海外支持
|
|||
/// - Parameters:
|
|||
/// - orderId: 订单id
|
|||
/// - userInfo: 用户自定义标识
|
|||
- (int)ostRetryTaskWithOrderId:( NSString * _Nonnull )orderId userInfo:(id _Nullable)userInfo; |
|||
|
|||
/// 删除任务,仅海外支持
|
|||
/// - Parameters:
|
|||
/// - orderId: 订单id
|
|||
/// - requestId: 客户端用于标记任务的唯一id,最大长度64字符,由客户端保证唯一性,服务回调结果时会会包含此参数
|
|||
/// - userInfo: 用户自定义标识
|
|||
- (int)ostCancelTaskWithOrderId:( NSString * _Nonnull )orderId requestId:( NSString * _Nonnull )requestId userInfo:(id _Nullable)userInfo; |
|||
|
|||
/// 删除任务,仅海外支持
|
|||
/// - Parameters:
|
|||
/// - orderId: 订单id
|
|||
/// - requestId: 客户端用于标记任务的唯一id,最大长度64字符,由客户端保证唯一性,服务回调结果时会会包含此参数
|
|||
/// - userInfo: 用户自定义标识
|
|||
- (int)ostDeleteTaskWithOrderId:( NSString * _Nonnull )orderId requestId:( NSString * _Nonnull )requestId userInfo:(id _Nullable)userInfo; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,35 @@ |
|||
//
|
|||
// RAASRError.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2024/8/9.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface RAASRError : NSObject |
|||
//common
|
|||
@property (nonatomic, assign) int code; |
|||
|
|||
@property (nonatomic, copy) NSString *errMsg; |
|||
|
|||
//国内
|
|||
@property (nonatomic, copy) NSString *orderId; |
|||
|
|||
@property (nonatomic, assign) int failType; |
|||
|
|||
//海外
|
|||
//海外
|
|||
@property (nonatomic, copy, readonly) NSString * ostTaskStatus; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * ostSid; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * ostTaskId; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * ostTaskType; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,59 @@ |
|||
//
|
|||
// RAASRResult.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2024/8/9.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
|
|||
@interface RAASRTransResult : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * segId; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * dst; |
|||
|
|||
@property (nonatomic, assign, readonly) int bg; |
|||
|
|||
@property (nonatomic, assign, readonly) int ed; |
|||
|
|||
@property (nonatomic, copy, readonly) NSArray <NSString *> * tags; |
|||
|
|||
@property (nonatomic, copy, readonly) NSArray <NSString *> * roles; |
|||
|
|||
@end |
|||
|
|||
@interface RAASRResult : NSObject |
|||
|
|||
//common
|
|||
@property (nonatomic, assign, readonly) int code; |
|||
@property (nonatomic, copy, readonly) NSString * orderResult; |
|||
|
|||
//国内
|
|||
@property (nonatomic, assign, readonly) int status; |
|||
@property (nonatomic, copy, readonly) NSString * orderId; |
|||
|
|||
@property (nonatomic, assign, readonly) long originalDuration; |
|||
|
|||
@property (nonatomic, assign, readonly) long realDuration; |
|||
|
|||
@property (nonatomic, assign, readonly) long expireTime; |
|||
|
|||
@property (nonatomic, assign, readonly) int taskEstimateTime; |
|||
|
|||
@property (nonatomic, copy, readonly) NSArray <RAASRTransResult *> * transResult; |
|||
|
|||
//海外
|
|||
@property (nonatomic, copy, readonly) NSString * ostTaskStatus; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * ostSid; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * ostTaskId; |
|||
|
|||
@property (nonatomic, copy, readonly) NSString * ostTaskType; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,149 @@ |
|||
//
|
|||
// RTASR.h
|
|||
// SparkChain_iOS
|
|||
// 实时语音转写
|
|||
// Created by pcfang on 2024/8/8.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
#import <SparkChain/SCEnums.h> |
|||
@class RTASRResult; |
|||
@class RTASRError; |
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@protocol RTASRCallback <NSObject> |
|||
|
|||
- (void)onResult:(RTASRResult *) result useInfo:(id _Nullable)userInfo; |
|||
|
|||
- (void)onError:(RTASRError *) error useInfo:(id _Nullable)userInfo; |
|||
@end |
|||
|
|||
@interface RTASR : NSObject |
|||
|
|||
//common
|
|||
@property (nonatomic, copy) NSString * lang; |
|||
|
|||
@property (nonatomic, copy) NSString * punc; |
|||
|
|||
@property (nonatomic, copy) NSString * pd; |
|||
|
|||
@property (nonatomic, assign) int vadMdn; |
|||
|
|||
//国内
|
|||
@property (nonatomic, copy) NSString * transType; |
|||
|
|||
@property (nonatomic, assign) int transStrategy; |
|||
|
|||
@property (nonatomic, copy) NSString * targetLanguage; |
|||
|
|||
@property (nonatomic, assign) int roleType; |
|||
|
|||
@property (nonatomic, assign) int engLangType; |
|||
|
|||
#pragma mark - region overseas params |
|||
@property (nonatomic, copy) NSString * ostContextId; |
|||
|
|||
@property (nonatomic, copy) NSString * ostUid; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDeviceId; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDeviceImei; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDeviceMac; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDeviceImsi; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDeviceOther; |
|||
|
|||
@property (nonatomic, copy) NSString * ostNetType; |
|||
|
|||
@property (nonatomic, copy) NSString * ostNetIsp; |
|||
|
|||
@property (nonatomic, copy) NSString * ostAppVer; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDid; |
|||
|
|||
//business params
|
|||
@property (nonatomic, copy) NSString * ostFormat; |
|||
|
|||
@property (nonatomic, copy) NSString * ostEncoding; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDomain; |
|||
|
|||
@property (nonatomic, copy) NSString * ostAccent; |
|||
|
|||
@property (nonatomic, copy) NSString * ostRequestId; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDwa; |
|||
|
|||
@property (nonatomic, assign) int ostEos; |
|||
|
|||
@property (nonatomic, copy) NSString * ostRf; |
|||
|
|||
@property (nonatomic, copy) NSString * ostResId; |
|||
|
|||
@property (nonatomic, assign) int ostVto; |
|||
|
|||
@property (nonatomic, assign) int ostNunum; |
|||
|
|||
@property (nonatomic, assign) int ostPptaw; |
|||
|
|||
@property (nonatomic, assign) int ostDyhotws; |
|||
|
|||
@property (nonatomic, assign) int ostSegMax; |
|||
|
|||
@property (nonatomic, assign) int ostSegMin; |
|||
|
|||
@property (nonatomic, assign) float ostSegWeight; |
|||
|
|||
@property (nonatomic, assign) int ostSpeexSize; |
|||
|
|||
@property (nonatomic, assign) int ostSpkdia; |
|||
|
|||
@property (nonatomic, assign) int ostPgsnum; |
|||
|
|||
@property (nonatomic, assign) int ostLanguageType; |
|||
|
|||
@property (nonatomic, copy) NSString * ostDhw; |
|||
|
|||
@property (nonatomic, assign) int ostDhwMod; |
|||
|
|||
@property (nonatomic, copy) NSArray<NSString *> * ostFeatureList; |
|||
|
|||
@property (nonatomic, assign) int ostRsgid; |
|||
|
|||
@property (nonatomic, assign) int ostRlang; |
|||
|
|||
@property (nonatomic, assign) int ostPgsFlashFreq; |
|||
|
|||
@property (nonatomic, copy) NSString * ostFrameId; |
|||
|
|||
- (void)addIntParam:(NSString *)key value:(int)value; |
|||
- (void)addBoolParam:(NSString *)key value:(BOOL)value; |
|||
- (void)addStringParam:(NSString *)key value:(NSString *)value; |
|||
|
|||
@property (nonatomic, weak) id<RTASRCallback> delegate; |
|||
|
|||
- (instancetype)init; |
|||
|
|||
- (instancetype)initWithRegion:(RegionType)region; |
|||
|
|||
- (instancetype)initWithSecretKey:(NSString *)secretKey; |
|||
|
|||
- (instancetype)initWithSecretKey:(NSString *)secretKey region:(RegionType)region; |
|||
|
|||
- (void)setOstPersonalization:(NSString *)key value:(NSString *)value; |
|||
|
|||
- (int)start; |
|||
|
|||
- (int)startWithUserInfo:(id _Nullable)userInfo; |
|||
|
|||
- (int)write:(NSData *)audioData; |
|||
|
|||
- (int)stop; |
|||
|
|||
- (int)stop:(BOOL)immediate; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,25 @@ |
|||
//
|
|||
// RTASRError.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2024/8/9.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface RTASRError : NSObject |
|||
|
|||
@property (nonatomic, assign) int code; |
|||
|
|||
@property (nonatomic, copy) NSString *errMsg; |
|||
|
|||
@property (nonatomic, copy) NSString *sid; |
|||
|
|||
//海外
|
|||
@property (nonatomic, copy) NSString *ostContextId; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,38 @@ |
|||
//
|
|||
// RTASRResult.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2024/8/9.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface RTASRTransResult : NSObject |
|||
|
|||
@property(nonatomic, assign, readonly) int status; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * src; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * dst; |
|||
|
|||
@end |
|||
|
|||
@interface RTASRResult : NSObject |
|||
|
|||
@property(nonatomic, assign, readonly) int status; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * data; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * raw; |
|||
|
|||
@property(nonatomic, copy, readonly) RTASRTransResult * transResult; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * ostContextId; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,20 @@ |
|||
//
|
|||
// SCEnums.h
|
|||
// SparkChain_iOS
|
|||
//
|
|||
// Created by pcfang on 2025/5/8.
|
|||
//
|
|||
|
|||
#ifndef SCEnums_h |
|||
#define SCEnums_h |
|||
|
|||
typedef enum : NSUInteger { |
|||
RegionDefault, |
|||
RegionSG, |
|||
RegionEU, |
|||
RegionCNLLM, |
|||
RegionMSFT |
|||
} RegionType; |
|||
|
|||
|
|||
#endif /* SCEnums_h */ |
|||
@ -0,0 +1,20 @@ |
|||
//
|
|||
// Segment.h
|
|||
// SparkChain_Mac
|
|||
//
|
|||
// Created by XX on 2024/5/11.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface Segment : NSObject |
|||
|
|||
@property (nonatomic) int score; |
|||
@property (nonatomic, copy) NSString *text; |
|||
@property (nonatomic, copy) NSString *lg; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,67 @@ |
|||
//
|
|||
// SparkChain.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 12.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
//! Project version number for SparkChain.
|
|||
FOUNDATION_EXPORT double SparkChainVersionNumber; |
|||
|
|||
//! Project version string for SparkChain.
|
|||
FOUNDATION_EXPORT const unsigned char SparkChainVersionString[]; |
|||
|
|||
#import <SparkChain/SparkChainConfig.h> |
|||
#import <SparkChain/SparkChainEntrance.h> |
|||
|
|||
#import <SparkChain/LLM.h> |
|||
#import <SparkChain/LLMEvent.h> |
|||
#import <SparkChain/LLMError.h> |
|||
#import <SparkChain/LLMResult.h> |
|||
#import <SparkChain/LLMConfig.h> |
|||
#import <SparkChain/Memory.h> |
|||
#import <SparkChain/LLMTools.h> |
|||
|
|||
#import <SparkChain/TTS.h> |
|||
#import <SparkChain/PersonateTTS.h> |
|||
//合成
|
|||
#import <SparkChain/OnlineTTS.h> |
|||
#import <SparkChain/TTSResult.h> |
|||
#import <SparkChain/TTSError.h> |
|||
|
|||
// 实时转写
|
|||
#import <SparkChain/RTASR.h> |
|||
#import <SparkChain/RTASRResult.h> |
|||
#import <SparkChain/RTASRError.h> |
|||
|
|||
// 录音文件转写
|
|||
#import <SparkChain/RAASR.h> |
|||
#import <SparkChain/RAASRResult.h> |
|||
#import <SparkChain/RAASRError.h> |
|||
|
|||
// Feature / 虚拟人 VC
|
|||
#import <SparkChain/Feature.h> |
|||
#import <SparkChain/FeatureResult.h> |
|||
#import <SparkChain/FeatureError.h> |
|||
#import <SparkChain/VC.h> |
|||
#import <SparkChain/VCResult.h> |
|||
#import <SparkChain/VCError.h> |
|||
#import <SparkChain/VCTextSeg.h> |
|||
|
|||
// 翻译
|
|||
#import <SparkChain/ITS.h> |
|||
#import <SparkChain/ITSResult.h> |
|||
#import <SparkChain/ITSError.h> |
|||
|
|||
//识别
|
|||
#import <SparkChain/ASR.h> |
|||
#import <SparkChain/ASRResult.h> |
|||
#import <SparkChain/ASRError.h> |
|||
#import <SparkChain/ASRHotwordsResult.h> |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
@ -0,0 +1,33 @@ |
|||
//
|
|||
// SparkChainConfig.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 12.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
#define chainProperty(returnType,name) property(nonatomic, readonly, copy) returnType (^name) |
|||
|
|||
@interface SparkChainConfig : NSObject |
|||
|
|||
@chainProperty(SparkChainConfig *,appID)(NSString * appID); |
|||
|
|||
@chainProperty(SparkChainConfig *,apiKey)(NSString * apiKey); |
|||
|
|||
@chainProperty(SparkChainConfig *,apiSecret)(NSString * apiSecret); |
|||
|
|||
@chainProperty(SparkChainConfig *,workDir)(NSString * workDir); |
|||
|
|||
@chainProperty(SparkChainConfig *,uid)(NSString * uid); |
|||
|
|||
@chainProperty(SparkChainConfig *,logLevel)(int logLevel); |
|||
|
|||
@chainProperty(SparkChainConfig *,logPath)(NSString * logPath); |
|||
|
|||
@chainProperty(SparkChainConfig *,apiType)(int apiType); |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,24 @@ |
|||
//
|
|||
// SparkChain.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 12.9.23.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
@class SparkChainConfig; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface SparkChain : NSObject |
|||
|
|||
+ (SparkChain *)getInst; |
|||
|
|||
- (int)init:(SparkChainConfig *)config; |
|||
|
|||
- (int)unInit; |
|||
|
|||
- (int)setConfig:(NSString *)key value:(void *)value; |
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,90 @@ |
|||
//
|
|||
// TTS.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 22.2.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
@class TTS; |
|||
@class TTSResult; |
|||
@class TTSError; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
typedef enum : NSUInteger { |
|||
Begin, |
|||
Continue, |
|||
End, |
|||
} Status; |
|||
|
|||
@protocol TTSCallbacks <NSObject> |
|||
|
|||
- (void)tts:(TTS *)tts onResult:(TTSResult *)result usrContext:(id)usrContext; |
|||
|
|||
- (void)tts:(TTS *)tts onError:(TTSError *)error usrContext:(id)usrContext; |
|||
@end |
|||
|
|||
@interface TTS : NSObject |
|||
|
|||
@property(nonatomic, weak) id<TTSCallbacks> cbs; |
|||
|
|||
@property(nonatomic, copy) NSString * vcn; |
|||
|
|||
@property(nonatomic, assign) int speed; |
|||
|
|||
@property(nonatomic, assign) int pitch; |
|||
|
|||
@property(nonatomic, assign) int volume; |
|||
|
|||
@property(nonatomic, assign) int reg; |
|||
|
|||
@property(nonatomic, assign) int rdn; |
|||
|
|||
// 以下海外不支持
|
|||
@property(nonatomic, assign) int sampleRate; |
|||
|
|||
@property(nonatomic, copy) NSString * encoding; |
|||
|
|||
@property(nonatomic, assign) int bitDepth; |
|||
|
|||
@property(nonatomic, assign) int channels; |
|||
|
|||
@property(nonatomic, assign) int frameSize; |
|||
|
|||
@property(nonatomic, assign) int bgs; |
|||
|
|||
@property(nonatomic, assign) BOOL rhy; |
|||
|
|||
@property(nonatomic, assign) int scn; |
|||
|
|||
@property(nonatomic, assign) BOOL version; |
|||
|
|||
@property(nonatomic, assign) int l5SilLen; |
|||
|
|||
@property(nonatomic, assign) int paragraphSilLen; |
|||
|
|||
- (instancetype)init; |
|||
|
|||
- (instancetype)initWithVcn:(NSString *)vcn; |
|||
|
|||
- (int)arun:(NSString *)text; |
|||
|
|||
- (int)arun:(NSString *)text userInfo:(id)userInfo; |
|||
|
|||
- (int)arun:(NSString *)text status:(Status)status; |
|||
|
|||
- (int)arun:(NSString *)text status:(Status)status userInfo:(id)userInfo; |
|||
|
|||
- (void)stop; |
|||
|
|||
|
|||
- (void)addIntParam:(NSString *)key value:(int)value; |
|||
|
|||
- (void)addBoolParam:(NSString *)key value:(BOOL)value; |
|||
|
|||
- (void)addStringParam:(NSString *)key value:(NSString *)value; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,22 @@ |
|||
//
|
|||
// TTSError.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 22.2.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface TTSError : NSObject |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property(nonatomic, assign, readonly) int code; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * errMsg; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,32 @@ |
|||
//
|
|||
// TTSResult.h
|
|||
// SparkChain
|
|||
//
|
|||
// Created by pcfang on 22.2.24.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface TTSResult : NSObject |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * sid; |
|||
|
|||
@property(nonatomic, assign, readonly) int seq; |
|||
|
|||
@property(nonatomic, copy, readonly) NSData * data; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * ced; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * pybuf; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * spell; |
|||
|
|||
@property(nonatomic, copy, readonly) NSString * version; |
|||
|
|||
@property(nonatomic, assign, readonly) int status; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,36 @@ |
|||
//
|
|||
// OCTableOcr.h
|
|||
// TABLE_OCR
|
|||
//
|
|||
// Created by xyzhang on 2024/6/4.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
@class TableOcr; |
|||
@class TableOcrResult; |
|||
@class TableOcrError; |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@protocol TableOcrDelegate <NSObject> |
|||
|
|||
- (void)tableOcr:(TableOcr *)tableOcr onResult:(TableOcrResult *)result usrContext:(id)usrContext; |
|||
|
|||
- (void)tableOcr:(TableOcr *)tableOcr onError:(TableOcrError *)error usrContext:(id)usrContext; |
|||
|
|||
@end |
|||
|
|||
@interface TableOcr : NSObject |
|||
|
|||
@property (nonatomic, weak) id<TableOcrDelegate> delegate; |
|||
@property (nonatomic, copy) NSString *resultEncoding; |
|||
@property (nonatomic, copy) NSString *resultCompress; |
|||
@property (nonatomic, copy) NSString *resultFormat; |
|||
|
|||
- (instancetype)init; |
|||
- (int)arun:(NSData *)imageData encoding:(NSString *)encoding userInfo:(id)userInfo; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,20 @@ |
|||
//
|
|||
// OCTableOcrError.h
|
|||
// TABLE_OCR
|
|||
//
|
|||
// Created by xyzhang on 2024/6/4.
|
|||
//
|
|||
|
|||
#import <Foundation/Foundation.h> |
|||
|
|||
NS_ASSUME_NONNULL_BEGIN |
|||
|
|||
@interface TableOcrError : NSObject |
|||
|
|||
@property (nonatomic, copy, readonly) NSString *sid; |
|||
@property (nonatomic, copy, readonly) NSString *errMsg; |
|||
@property (nonatomic, assign, readonly) int code; |
|||
|
|||
@end |
|||
|
|||
NS_ASSUME_NONNULL_END |
|||
@ -0,0 +1,24 @@ |
|||
//
|
|||
// OCTableOcrExtension.h
|
|||
// TABLE_OCR
|
|||
//
|
|||
// Created by xyzhang on 2024/6/4.
|
|||
//
|
|||
|
|||
#import "TableOcr.h" |
|||
#import "TableOcrResult.h" |
|||
#import "TableOcrError.h" |
|||
#include "sc_tableOCR.h" |
|||
|
|||
@interface TableOcr () |
|||
- (instancetype)initWithTableOcr:(SparkChain::TableOCR *)tableOcr; |
|||
- (SparkChain::TableOCR *)tableOcrRef; |
|||
@end |
|||
|
|||
@interface TableOcrResult () |
|||
- (instancetype)initWithResult:(SparkChain::TableOCRResult *)result; |
|||
@end |
|||
|
|||
@interface TableOcrError () |
|||
- (instancetype)initWithError:(SparkChain::TableOCRError *)error; |
|||
@end |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue