Skip to main content

Python SDK for LingxinAI Psychology Open APIs

Project description

LingxinAI Psychology Python SDK

Python SDK for LingxinAI Psychology Open APIs.

Install

pip install lingxinai-psychology

Quick Start

from lingxinai.psychology import PsychologyClient
from lingxinai.psychology.types import OpenStudentQueryRequest

client = PsychologyClient.builder() \
    .admin("your-api-key", "your-api-secret") \
    .build()

students = client.open_api().student().list(OpenStudentQueryRequest(
    orgCode="school001",
    pageNum=0,
    pageSize=20,
))

print(students.content)

Streaming Chat

Use completionsStream when the reply must be displayed as it is generated.

from lingxinai.psychology.types import ChatQueryRequest

for chunk in student_client.open_api().chat().completionsStream(ChatQueryRequest(
    botId=237,
    content="我最近压力很大,想聊一聊",
)):
    print(chunk, end="", flush=True)
print()

Client Identity

Create one client per identity. Do not mix admin, user, student, or parent calls on the same client.

admin_client = PsychologyClient.builder() \
    .admin("your-api-key", "your-api-secret") \
    .build()

user_client = PsychologyClient.builder() \
    .user("your-api-key", "your-api-secret", "external-user-001") \
    .build()

student_client = PsychologyClient.builder() \
    .student("your-api-key", "your-api-secret", 10001) \
    .build()

parent_client = PsychologyClient.builder() \
    .access_token(parent_login_response.token) \
    .build()

API Groups

  • auth() - login helpers
  • org() - organization APIs
  • dept() - department/class APIs
  • student() - student APIs
  • orgUser() - organization staff APIs
  • device() - device APIs
  • bot() - bot APIs
  • chat() - chat APIs
  • course() - micro course APIs
  • algo() - HTTP ASR/TTS and realtime ASR/TTS WebSocket APIs
  • crisis() - crisis warning APIs
  • meditation() - meditation APIs
  • overview() - dashboard/statistics APIs
  • parent() - parent-side APIs
  • quickInterview() - quick interview APIs
  • activity() - activity APIs
  • scale() - scale/interview runtime APIs

Realtime ASR

from lingxinai.psychology.types import RealtimeAsrOptions

ws = student_client.open_api().algo().realtimeAsr(RealtimeAsrOptions(
    voiceFormat=1,
    inputSampleRate=16000,
))

ws.send('{"type":"start"}')
ws.send(audio_chunk, opcode=0x2)
ws.send('{"type":"end"}')
print(ws.recv())
ws.close()

Bidirectional TTS

Use bidirectionalTts when text arrives in chunks and audio must be streamed back at the same time.

import json

ws = student_client.open_api().algo().bidirectionalTts()
ws.send(json.dumps({"type": "start", "voiceCode": "zh_female_linjianvhai_moon_bigtts", "format": "mp3"}))
ws.send(json.dumps({"type": "text", "text": "我们先做一次简单的"}))
ws.send(json.dumps({"type": "text", "text": "放松练习。"}))
ws.send(json.dumps({"type": "end"}))
ws.close()

Realtime ASR/TTS Smoke Test

The repository includes a script for checking both realtime WebSocket APIs. It reads credentials from .env.local, writes TTS audio to tmp/realtime-tts-output.mp3, and feeds realtime-voice-smoke.wav to realtime ASR.

python test/realtime_asr_tts_stream.py

Optional arguments:

python test/realtime_asr_tts_stream.py \
  --asr-audio /path/to/16k-mono-pcm.wav \
  --voice-code zh_female_linjianvhai_moon_bigtts \
  --text "你好,这是实时语音合成测试。"

Verification

python -m unittest discover -s test
python -m build --sdist --wheel
python -m twine check dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lingxinai_psychology-1.0.5.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lingxinai_psychology-1.0.5-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file lingxinai_psychology-1.0.5.tar.gz.

File metadata

  • Download URL: lingxinai_psychology-1.0.5.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for lingxinai_psychology-1.0.5.tar.gz
Algorithm Hash digest
SHA256 16df5cd9c0391f724e39cae713029df4efc5d00ad1b9745810443623af4c4cbb
MD5 42630de0856a70c4b2cbe54bb60c4e31
BLAKE2b-256 513cce9b18ac7b63288516fc97fa34b6104f71d37c7f15773c61549282a5625a

See more details on using hashes here.

File details

Details for the file lingxinai_psychology-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for lingxinai_psychology-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8d57a8e7b9233d190cc2f3d05a4822354392ee05fe05099a887af170eb2dda62
MD5 bf14ceda81e0c1b4c4ba29250a7cd2d6
BLAKE2b-256 dd0e601142d736bf04e75b1a542b04bdb44a0ced28da7691ec50c3cf06647c1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page