yunmao
v0.1.10
Published
Official TypeScript SDK for Yunmao APIs
Readme
Yunmao TypeScript SDK
Official TypeScript SDK for Yunmao APIs. Requires Node.js 18+ or a runtime with fetch, FormData, and Blob.
Install
npm install yunmaoQuick Start
import { YunmaoClient } from "yunmao";
const client = new YunmaoClient({
apiKey: "<YOUR_API_KEY>",
baseURL: "<YOUR_BASE_URL>",
});Pass the appropriate baseURL for your environment.
For API methods, supported parameters, and full examples, see the official Yunmao developer documentation.
Realtime ASR
const stream = await client.asr.stream({
language_hint: "<LANGUAGE_HINT>",
audio_format: "pcm",
sample_rate: 16000,
onStarted: (event) => console.log(event.request_id),
onPartial: (event) => console.log(event.text),
onFinal: (event) => console.log(event.text),
onError: (error) => console.log(error.code, error.message),
});
stream.write(pcm16Chunk);
await stream.end();client.asr.stream() uses Authorization: Bearer <YOUR_API_KEY> in Node.js. Browser WebSocket clients can pass auth: "query" if custom headers are unavailable.
The returned stream also supports async iteration:
for await (const event of stream) {
console.log(event.type);
}Errors
import { YunmaoAPIError } from "yunmao";
try {
// Call a Yunmao API method here.
} catch (error) {
if (error instanceof YunmaoAPIError) {
console.log(error.statusCode);
console.log(error.code);
console.log(error.message);
console.log(error.requestId);
}
}The SDK preserves HTTP status, Yunmao code, server message, request id when provided, and the parsed response body.
Test
npm install
npm run typecheck
npm testAutomated tests use mocks and do not call paid APIs.
