Class: ModerationAPI::Resources::Content
- Inherits:
-
Object
- Object
- ModerationAPI::Resources::Content
- Defined in:
- lib/moderation_api/resources/content.rb,
sig/moderation_api/resources/content.rbs
Instance Method Summary collapse
-
#initialize(client:) ⇒ Content
constructor
private
A new instance of Content.
-
#stream(sec_web_socket_protocol:, request_options: {}) ⇒ nil
Open a WebSocket to moderate live voice/call audio in real time.
-
#submit(content:, author_id: nil, channel: nil, client_action: nil, content_id: nil, conversation_id: nil, do_not_store: nil, metadata: nil, meta_type: nil, policies: nil, timestamp: nil, request_options: {}) ⇒ ModerationAPI::Models::ContentSubmitResponse
Some parameter documentations has been truncated, see Models::ContentSubmitParams for more details.
Constructor Details
#initialize(client:) ⇒ Content
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Content.
94 95 96 |
# File 'lib/moderation_api/resources/content.rb', line 94 def initialize(client:) @client = client end |
Instance Method Details
#stream(sec_web_socket_protocol:, request_options: {}) ⇒ nil
Open a WebSocket to moderate live voice/call audio in real time. Speech is transcribed and each finalized utterance is moderated by your enabled text policies; you receive a verdict per utterance as it's spoken.
This is a WebSocket upgrade, not a regular HTTP call. The request body below
documents the frames you send over the socket; the 101 response documents
the events you receive.
- Auth:
Authorization: Bearer <api_key>on the upgrade. A missing/invalid key closes4401; voice not enabled on the plan/channel closes4403. - Subprotocol: request
moderationapi.v1. - Flow: send one
startframe, thenmediaframes as audio arrives, thenstop(or disconnect). You receivesession.started,utterance.finalper utterance, optionalutterance.partial/warning, andsession.ended. - Close codes:
1000normal ·1011server error ·4400bad request ·4401auth failed ·4403voice not enabled ·4429concurrency limit.
See the Real-time voice guide for the full walkthrough and code examples.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/moderation_api/resources/content.rb', line 36 def stream(params) parsed, = ModerationAPI::ContentStreamParams.dump_request(params) path = @client.base_url_overridden? ? "stream" : "wss://voice.moderationapi.com/v1/stream" @client.request( method: :get, path: path, headers: parsed.transform_keys(sec_web_socket_protocol: "sec-websocket-protocol"), model: NilClass, options: ) end |
#submit(content:, author_id: nil, channel: nil, client_action: nil, content_id: nil, conversation_id: nil, do_not_store: nil, metadata: nil, meta_type: nil, policies: nil, timestamp: nil, request_options: {}) ⇒ ModerationAPI::Models::ContentSubmitResponse
Some parameter documentations has been truncated, see Models::ContentSubmitParams for more details.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/moderation_api/resources/content.rb', line 80 def submit(params) parsed, = ModerationAPI::ContentSubmitParams.dump_request(params) @client.request( method: :post, path: "moderate", body: parsed, model: ModerationAPI::Models::ContentSubmitResponse, options: ) end |