@lingxinai/psychology
v1.0.5
Published
TypeScript SDK for LingxinAI Psychology Open APIs
Readme
LingxinAI Psychology NPM SDK
TypeScript SDK for LingxinAI Psychology Open APIs.
Install
npm install @lingxinai/psychologyQuick Start
import { PsychologyClient } from "@lingxinai/psychology";
const client = PsychologyClient.builder()
.admin("your-api-key", "your-api-secret")
.build();
const students = await client.openApi().student().list({
orgCode: "school001",
pageNum: 0,
pageSize: 20
});
console.log(students.content);Client Identity
Create one client per identity. Do not mix admin, user, student, or parent calls on the same client.
const adminClient = PsychologyClient.builder()
.admin("your-api-key", "your-api-secret")
.build();
const userClient = PsychologyClient.builder()
.user("your-api-key", "your-api-secret", "external-user-001")
.build();
const studentClient = PsychologyClient.builder()
.student("your-api-key", "your-api-secret", 10001)
.build();For parent login or other flows that already return a platform access token:
const parentClient = PsychologyClient.builder()
.accessToken(parentLoginResponse.token)
.build();API Groups
auth()- login helpersorg()- organization APIsdept()- department/class APIsstudent()- student APIsorgUser()- organization staff APIsdevice()- device APIsbot()- bot APIschat()- chat APIscourse()- micro course APIsalgo()- HTTP ASR/TTS and realtime ASR/TTS WebSocket APIscrisis()- crisis warning APIsmeditation()- meditation APIsoverview()- dashboard/statistics APIsparent()- parent-side APIsquickInterview()- quick interview APIsactivity()- activity APIsscale()- scale/interview runtime APIs
Realtime ASR
Realtime ASR returns a Promise<WebSocket> because the SDK prepares the authenticated connection first.
const ws = await studentClient.openApi().algo().realtimeAsr({
voiceFormat: 1,
inputSampleRate: 16000
});
ws.on("open", () => {
ws.send(JSON.stringify({ type: "start" }));
ws.send(audioChunk);
ws.send(JSON.stringify({ type: "end" }));
});
ws.on("message", (message) => {
console.log(message.toString());
});Bidirectional TTS
Use bidirectionalTts when text arrives in chunks and audio must be streamed back at the same time.
const ws = await studentClient.openApi().algo().bidirectionalTts();
ws.on("open", () => {
ws.send(JSON.stringify({ type: "start", voiceCode: "zh_female_linjianvhai_moon_bigtts", format: "mp3" }));
ws.send(JSON.stringify({ type: "text", text: "我们先做一次简单的" }));
ws.send(JSON.stringify({ type: "text", text: "放松练习。" }));
ws.send(JSON.stringify({ type: "end" }));
});
ws.on("message", (message) => {
console.log(Buffer.isBuffer(message) ? message.length : message.toString());
});Verification
npm run verify
npm audit --omit=dev
npm pack --dry-run