跳到正文
OneSay 开发者

SDK 与 API 参考

JavaScript SDK参考

软件包:@onesay/sdk;许可证:Apache-2.0。

软件包:@onesay/sdk;许可证:Apache-2.0。

环境

每个环境都有自己的中枢API和Realtime WebSocket地址。

环境中枢APIRealtime WebSocket
生产环境https://api.onesay.com/v1wss://realtime.onesay.com/v1

要连接其他地域的节点,请用配置中的地址调用setCustomEndpoints,并使用environment: "custom"。

房间事件

SDK的事件名称,以及它对应的OneSay事件。

  • Connected -> room.connected
  • Disconnected -> room.disconnected
  • Reconnecting -> room.reconnecting
  • Reconnected -> room.reconnected
  • ParticipantJoined -> participant.joined
  • ParticipantLeft -> participant.left
  • SignalOpened -> signal.opened
  • SignalEnded -> signal.ended
  • Error -> error

任务事件

SDK的事件名称,以及它对应的OneSay事件。

  • Created -> task.created
  • Started -> task.started
  • TranscriptPartial -> artifact.delta
  • TranscriptFinal -> artifact.finalized
  • Completed -> task.completed
  • Failed -> task.failed
  • Cancelled -> task.cancelled

在浏览器中,SDK只通过你提供的Token提供器进行身份验证,从不使用密钥。语音任务发送你传入的音频:16000 Hz单声道pcm_s16le;SDK不会为此打开麦克风,也从不静默丢弃音频。SDK还提供转换采样缓冲区的辅助函数。

语音任务

  • 入口:client.tasks.create, client.tasks.get, client.tasks.list, client.tasks.cancel, RealtimeClient
  • 传输:onesay.realtime.v1 WebSocket with canonical PCM frames, contiguous ACK, unacked-only replay and bounded resume
  • 结果:Task and Artifact readback

实时语音(RTC)

  • 入口:client.rtc.connect, client.rtc.get, client.rtc.revoke, client.rtc.endPublication, client.rtc.agents.create, client.rtc.agents.get, client.rtc.agents.stop
  • 传输:OneSay RTC session over the locked native SDK, loaded lazily on the first RTC operation
  • 结果:publications, subscriptions, packets, streams, RPC, data tracks and explicit Agent executions

RTC会话状态

  • connected
  • reconnecting
  • closed

会话状态是这个客户端观察到的状态。每次授权都由服务端决定;只有服务端报告撤销已生效,撤销才算完成。

能力

能力支持情况说明
语音任务(WSS、ACK、重放、恢复)支持Supported (browser, Node)
RTC音频支持Publish, subscribe, mute, playback (browser)
数据包支持Send and receive
数据流支持Send and receive
RPC支持Call and handle
DataTrack支持Supported (livekit-client 2.22.3)
Agent支持Explicit Agent executions and read-only Agent state
状态、设备、错误和释放支持Session state, quality, microphone selection, OneSay errors, close
所选模式的媒体加密视环境而定Conditional: where the browser can run the packaged worker

不公开:native room, track and participant objects;native token or connection material;native SDK types;an escape hatch to the native SDK。不支持的能力会返回明确的错误。

参见SDK能力和兼容性。