优谷雅言开放平台
2.1.0语音评测 SDK
五端 SDK 与两个声通平替层,覆盖整段评测,实时评测,语音合成与报告查询。写操作自动带幂等键,网络抖动时按策略重试,实时评测断线后整段重放,重试与重连都不会重复计费。
当前版本
2.1.0
服务基址
open.shengzhiai.com
许可
Apache-2.0
QuickStart.java
try (YuguClient client = YuguClient.builder()
.apiKey(System.getenv("YUGU_APP_KEY"), System.getenv("YUGU_SECRET_KEY"))
.build()) {
EvalResult r = client.evaluate(Path.of("audio.wav"),
new EvaluateConfig(EvaluateConfig.CORE_SENTENCE, "今天天气很好", "zh-CN"));
System.out.println("总分 " + r.getOverall());
System.out.println("发音 " + r.getDims().getPronunciation());
System.out.println("流利度 " + r.getDims().getFluency());
System.out.println("完整度 " + r.getDims().getIntegrity());
r.getWords().forEach(w -> System.out.println(w.getWord() + " " + w.getScores().getOverall()));
} catch (YuguException e) {
System.err.println(e.getCategory() + " " + e.getCode() + " " + e.getRawMessage());
}Kotlin
val client = YuguClient.builder()
.auth(Auth.appKey("YOUR_APP_KEY", "YOUR_SECRET_KEY"))
.build()
thread {
val result = client.evaluate(
EvaluateConfig(CoreType.SENTENCE, "今天天气很好", Language.ZH_CN),
File(filesDir, "sample.wav"),
)
Log.i("yugu", "总分 ${result.overall},发音 ${result.dimensions.pronunciation}")
}Swift
import YuguSDK
// 创建客户端,App 内复用同一个实例
let client = YuguClient(options: YuguClientOptions(
auth: .appKey("<appKey>", secretKey: "<secretKey>")))
// 评测一段 16 kHz 单声道 WAV
let config = EvaluateConfig(coreType: .sentence, referenceText: "今天天气很好", language: "zh-CN")
let result = try await client.evaluate(audio: .file(wavURL), config: config)
// 读取分数
print("总分", result.overall ?? 0)
print("流利度", result.dimensions.fluency ?? 0, "完整度", result.dimensions.integrity ?? 0)
for word in result.words {
print(word.word ?? "", word.overall ?? 0)
}quickstart.mjs
import { readFile } from 'node:fs/promises';
import { YuguClient } from '@shengzhiai/yugu-web-sdk';
const client = new YuguClient({
appKey: process.env.YUGU_APP_KEY,
secretKey: process.env.YUGU_SECRET_KEY,
});
const audio = await readFile(process.argv[2] || 'hello.wav');
const result = await client.evaluate(audio, {
coreType: 'sentence',
referenceText: '今天天气很好',
language: 'zh-CN',
});
console.log('总分', result.overall, '各维度', result.dims);
await client.close();JavaScript
const { YuguClient } = require('@shengzhiai/yugu-miniprogram-sdk');
const client = new YuguClient({
auth: { token: '<由自有服务端下发的短期 token>' },
});
const recorder = client.createRecorder();
const session = client.streamEvaluate(
{ coreType: 'sentence', referenceText: '今天天气很好', language: 'zh-CN' },
{
onResult(result) { console.log('总分', result.overall); },
onError(err) { console.log('评测失败', err.code, err.message); },
},
);
recorder.pipeTo(session);
recorder.start();
// 用户读完后
recorder.stop();Shell
# 原生整段评测。被签名参数只有 config 段的 JSON 原文
CONFIG='{"coreType":"sentence","referenceText":"今天天气很好","language":"zh-CN"}'
TS=$(date +%s)
NONCE=$(openssl rand -hex 16)
SIGN=$(printf 'config=%s' "$CONFIG" | openssl dgst -sha256 -hmac "$YUGU_SECRET_KEY" -binary | base64)
curl -sS https://open.shengzhiai.com/api/v1/evaluate \
-H "X-App-Key: $YUGU_APP_KEY" \
-H "X-Timestamp: $TS" \
-H "X-Nonce: $NONCE" \
-H "X-Signature: $SIGN" \
-H "Idempotency-Key: $(openssl rand -hex 16)" \
-F "audio=@audio.wav" \
-F "config=$CONFIG;type=application/json"