PageSourceSearch

https://static.inworld.ai/466fe559/static/js/ttsBinaryProtocol.BrM6GeCL.js

js inworld.ai collected 2026-10-01 09:01:21 UTC 7,188 bytes, 1 lines download raw bytes

1import{ci as m}from"./bootstrap.KUFis_Od.js";import{cj as U,ck as _}from"./bootstrap.KUFis_Od.js";import"./vendor-core.DkahmlU8.js";import"./vendor-mui-x.BZ8Y4adA.js";import"./vendor-firebase.dbYXL2Q0.js";const f=16*1024*1024,p=new TextDecoder;class o extends Error{constructor(e){super(e),this.name="TTSBinaryProtocolError"}}class w extends Error{constructor(e,r){super(r),this.name="TTSBinaryAPIError",this.code=e}}const b=new Uint8Array;class c{constructor(e){this.data=e,this.position=0}get done(){return this.position===this.data.length}ensureAvailable(e){if(e<0||this.position+e>this.data.length)throw new o("Truncated protobuf message")}readUnsignedVarint(){let e=0,r=1;for(let t=0;t<10;t++){this.ensureAvailable(1);const s=this.data[this.position++];if(t===9&&s>1)throw new o("Invalid protobuf varint");const n=s&127;if(n!==0&&r>(Number.MAX_SAFE_INTEGER-e)/n)throw new o("Protobuf integer exceeds JavaScript safe integer range");if(e+=n*r,(s&128)===0)return e;r*=128}throw new o("Invalid protobuf varint")}readNumber(){return this.readUnsignedVarint()}skipUnsignedVarint(){for(let e=0;e<10;e++){this.ensureAvailable(1);const r=this.data[this.position++];if(e===9&&r>1)throw new o("Invalid protobuf varint");if((r&128)===0)return}throw new o("Invalid protobuf varint")}readTag(){const e=this.readNumber(),r=Math.floor(e/8),t=e%8;if(r===0)throw new o("Invalid protobuf field number 0");return{fieldNumber:r,wireType:t}}readBytes(){const e=this.readNumber();this.ensureAvailable(e);const r=this.data.subarray(this.position,this.position+e);return this.position+=e,r}readString(){return p.decode(this.readBytes())}readFloat(){this.ensureAvailable(4);const e=new DataView(this.data.buffer,this.data.byteOffset+this.position,4).getFloat32(0,!0);return this.position+=4,e}skipField(e,r){switch(r){case 0:this.skipUnsignedVarint();return;case 1:this.ensureAvailable(8),this.position+=8;return;case 2:this.readBytes();return;case 3:for(;!this.done;){const t=this.readTag();if(t.wireType===4){if(t.fieldNumber!==e)throw new o("Mismatched protobuf group terminator");return}this.skipField(t.fieldNumber,t.wireType)}throw new o("Truncated protobuf group");case 4:throw new o("Unexpected protobuf group terminator");case 5:this.ensureAvailable(4),this.position+=4;return;default:throw new o(`Unsupported protobuf wire type ${r}`)}}}const a=(i,e,r)=>{if(e!==r)throw new o(`Invalid wire type ${e} for protobuf field ${i}`)},g=i=>{const e=new c(i);let r="",t=0;for(;!e.done;){const{fieldNumber:s,wireType:n}=e.readTag();switch(s){case 1:a(s,n,0),t=e.readNumber();break;case 2:a(s,n,2),r=e.readString();break;default:e.skipField(s,n)}}return{modelId:r,processedCharactersCount:t}},u=(i,e,r,t)=>{if(r===5){t.push(i.readFloat());return}a(e,r,2);const s=new c(i.readBytes());for(;!s.done;)t.push(s.readFloat())},y=i=>{const e=new c(i),r={words:[],wordStartTimeSeconds:[],wordEndTimeSeconds:[]};for(;!e.done;){const{fieldNumber:t,wireType:s}=e.readTag();switch(t){case 1:a(t,s,2),r.words.push(e.readString());break;case 2:u(e,t,s,r.wordStartTimeSeconds);break;case 3:u(e,t,s,r.wordEndTimeSeconds);break;default:e.skipField(t,s)}}return r},T=i=>{const e=new c(i);let r;for(;!e.done;){const{fieldNumber:t,wireType:s}=e.readTag();t===1?(a(t,s,2),r=y(e.readBytes())):e.skipField(t,s)}return r?{wordAlignment:r}:void 0},B=i=>{const e=new c(i);let r=b,t,s;for(;!e.done;){const{fieldNumber:n,wireType:d}=e.readTag();switch(n){case 1:a(n,d,2),r=e.readBytes();break;case 2:a(n,d,2),t=g(e.readBytes());break;case 3:a(n,d,2),s=T(e.readBytes());break;default:e.skipField(n,d)}}return{audioContent:r,...t?{usage:t}:{},...s?{timestampInfo:s}:{}}},S=i=>{const e=new c(i);let r=0,t="";for(;!e.done;){const{fieldNumber:s,wireType:n}=e.readTag();switch(s){case 1:a(s,n,0),r=e.readNumber();break;case 2:a(s,n,2),t=e.readString();break;default:e.skipField(s,n)}}return{code:r,message:t}},k=i=>{const e=new c(i);let r=0,t=0;for(;!e.done;){const{fieldNumber:s,wireType:n}=e.readTag();switch(s){case 1:a(s,n,0),r=e.readNumber();break;case 2:a(s,n,0),t=e.readNumber();break;default:e.skipField(s,n)}}return{inputTokens:r,outputTokens:t}},v=i=>{const e=new c(i);let r;for(;!e.done;){const{fieldNumber:t,wireType:s}=e.readTag();let n;switch(t){case 1:a(t,s,2),n={kind:"synthesis",response:B(e.readBytes())};break;case 2:a(t,s,2),n={kind:"duplex",payload:e.readBytes()};break;case 3:a(t,s,2),n={kind:"error",error:S(e.readBytes())};break;case 4:a(t,s,2),n={kind:"vertexBillingUsage",usage:k(e.readBytes())};break;default:e.skipField(t,s)}if(n){if(r)throw new o("TTS binary frame contains multiple response payloads");r=n}}return r};class F{constructor(){this.frameLength=0,this.frameLengthBytes=0,this.frameLengthMultiplier=1,this.frameChunks=[],this.receivedFrameBytes=0,this.finished=!1}push(e){if(this.finished)throw new o("Cannot decode data after the TTS binary stream ended");const r=[];let t=0;for(;t<e.length;){if(this.expectedFrameBytes===void 0){if(this.frameLengthBytes===5
1)throw new o("Invalid TTS binary frame length");const d=e[t++];if(this.frameLength+=(d&127)*this.frameLengthMultiplier,this.frameLengthMultiplier*=128,this.frameLengthBytes++,(d&128)!==0){if(this.frameLengthBytes===5)throw new o("Invalid TTS binary frame length");continue}if(this.frameLength>f)throw new o(`TTS binary frame exceeds ${f} bytes`);this.expectedFrameBytes=this.frameLength,this.frameLength=0,this.frameLengthBytes=0,this.frameLengthMultiplier=1}const s=this.expectedFrameBytes-this.receivedFrameBytes,n=Math.min(t+s,e.length);if(n>t&&(this.frameChunks.push(e.subarray(t,n)),this.receivedFrameBytes+=n-t,t=n),this.receivedFrameBytes===this.expectedFrameBytes){const d=this.frameChunks.length===1?this.frameChunks[0]:l(this.frameChunks),h=v(d);h&&r.push(h),this.expectedFrameBytes=void 0,this.frameChunks=[],this.receivedFrameBytes=0}}return r}finish(){if(!this.finished&&(this.finished=!0,this.frameLengthBytes!==0||this.expectedFrameBytes!==void 0))throw new o("Truncated TTS binary frame")}}const l=i=>{const e=i.reduce((s,n)=>s+n.length,0),r=new Uint8Array(e);let t=0;for(const s of i)r.set(s,t),t+=s.length;return r},A=i=>{const e=i.byteOffset===0&&i.byteLength===i.buffer.byteLength&&i.buffer instanceof ArrayBuffer?i.buffer:Uint8Array.from(i).buffer;return m(e)},L=i=>{const e=new F,r=e.push(i);e.finish();const t=[];let s,n=!1;const d={words:[],wordStartTimeSeconds:[],wordEndTimeSeconds:[]};for(const h of r){if(h.kind==="error")throw new w(h.error.code,h.error.message);h.kind==="synthesis"&&(t.push(h.response.audioContent),h.response.usage&&(s=h.response.usage),h.response.timestampInfo&&(n=!0,d.words.push(...h.response.timestampInfo.wordAlignment.words),d.wordStartTimeSeconds.push(...h.response.timestampInfo.wordAlignment.wordStartTimeSeconds),d.wordEndTimeSeconds.push(...h.response.timestampInfo.wordAlignment.wordEndTimeSeconds)))}if(t.length===0)throw new o("TTS binary response contains no synthesis payload");return{audioContent:A(l(t)),...s?{usage:s}:{},...n?{timestampInfo:{wordAlignment:d}}:{}}};export{w as TTSBinaryAPIError,F as TTSBinaryFrameDecoder,o as TTSBinaryProtocolError,f as TTS_BINARY_MAX_FRAME_BYTES,U as TTS_BINARY_MEDIA_TYPE,_ as TTS_RESPONSE_PROTOCOL,L as decodeTTSBinarySynthesisResponse};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.