@jokio/sdk 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8566,10 +8566,14 @@ const oi = {
8566
8566
  storage: new ii()
8567
8567
  }, Mr = new Fr(oi), Jo = {
8568
8568
  setup(r) {
8569
- (r.authUrl || r.storage) && (this.auth = new Fr({
8570
- authUrl: r.authUrl ?? this.auth.url,
8571
- storage: r.storage ?? this.storage
8572
- })), (r.natsUrl || r.storage) && (this.nats = new Tr({
8569
+ if (r.authUrl || r.storage) {
8570
+ const e = this.auth.onUserDataUpdate;
8571
+ this.auth = new Fr({
8572
+ authUrl: r.authUrl ?? this.auth.url,
8573
+ storage: r.storage ?? this.storage
8574
+ }), this.auth.onUserDataUpdate = e;
8575
+ }
8576
+ (r.natsUrl || r.storage) && (this.nats = new Tr({
8573
8577
  natsUrl: r.natsUrl ?? this.nats.url,
8574
8578
  auth: this.auth
8575
8579
  }));
@@ -36,4 +36,4 @@ Path:ssml\r
36
36
  Content-Type:application/json; charset=utf-8\r
37
37
  Path:speech.config\r
38
38
  \r
39
- {"context":{"synthesis":{"audio":{"metadataoptions":{"sentenceBoundaryEnabled":false,"wordBoundaryEnabled":true},"outputFormat":"audio-24khz-48kbitrate-mono-mp3"}}}}`,Eo=(r,e,t={})=>{var o;t.pitch=(o=t.pitch)==null?void 0:o.replace("hz","Hz");const s=t.pitch||"0Hz",i=t.rate||"0%",n=t.volume||"0%";return`<speak version='1.0' xml:lang='en-US'><voice name='${e}'><prosody pitch='${s}' rate='${i}' volume='${n}'>${r}</prosody></voice></speak>`};function Ao(r,e){for(let t=0;t<=r.length-e.length;t++){let s=!0;for(let i=0;i<e.length;i++)if(r[t+i]!==e[i]){s=!1;break}if(s)return t}return-1}class Po{constructor(e){this.config=e}async getAudioBuffer(e,t){const s=await fetch(`${this.config.voicevoxUrl}/audio_query?text=${encodeURIComponent(e)}&speaker=${t||3}`,{method:"POST",headers:{Accept:"application/json"}});if(!s.ok)throw new Error(`Audio query failed: ${s.statusText}`);const i=await s.json(),n=await fetch(`${this.config.voicevoxUrl}/synthesis?speaker=${t}`,{method:"POST",headers:{Accept:"audio/wav","Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.body)return null;const o=n.body.getReader(),a=[];for(;;){const{done:y,value:x}=await o.read();if(y)break;a.push(x)}const d=a.reduce((y,x)=>y+x.length,0),p=new Uint8Array(d);let g=0;for(const y of a)p.set(y,g),g+=y.length;return p.buffer}async getAudio(e,t){return this.getAudioBuffer(e,t).then(s=>s?Gr(s):null)}async getVoices(){return(await fetch(`${this.config.voicevoxUrl}/speakers`).then(t=>t.json())).flatMap(t=>t.styles.map(s=>({id:s.id.toString(),locale:"ja-JP",description:`${t.name} - ${s.name}`})))}}const Kr={debug:!1,authUrl:"https://auth.jok.io",natsUrl:"https://nats.jok.io",storage:new zr},Vr=new er(Kr),Oo={setup(r){(r.authUrl||r.storage)&&(this.auth=new er({authUrl:r.authUrl??this.auth.url,storage:r.storage??this.storage})),(r.natsUrl||r.storage)&&(this.nats=new Ls({natsUrl:r.natsUrl??this.nats.url,auth:this.auth}))},auth:Vr,storage:new zr,tts:new So,nats:new Ls({...Kr,auth:Vr}),crypto:new yi};me.NatsService=Ls,me.VoicevoxTtsService=Po,me.jok=Oo,Object.defineProperty(me,Symbol.toStringTag,{value:"Module"})});
39
+ {"context":{"synthesis":{"audio":{"metadataoptions":{"sentenceBoundaryEnabled":false,"wordBoundaryEnabled":true},"outputFormat":"audio-24khz-48kbitrate-mono-mp3"}}}}`,Eo=(r,e,t={})=>{var o;t.pitch=(o=t.pitch)==null?void 0:o.replace("hz","Hz");const s=t.pitch||"0Hz",i=t.rate||"0%",n=t.volume||"0%";return`<speak version='1.0' xml:lang='en-US'><voice name='${e}'><prosody pitch='${s}' rate='${i}' volume='${n}'>${r}</prosody></voice></speak>`};function Ao(r,e){for(let t=0;t<=r.length-e.length;t++){let s=!0;for(let i=0;i<e.length;i++)if(r[t+i]!==e[i]){s=!1;break}if(s)return t}return-1}class Po{constructor(e){this.config=e}async getAudioBuffer(e,t){const s=await fetch(`${this.config.voicevoxUrl}/audio_query?text=${encodeURIComponent(e)}&speaker=${t||3}`,{method:"POST",headers:{Accept:"application/json"}});if(!s.ok)throw new Error(`Audio query failed: ${s.statusText}`);const i=await s.json(),n=await fetch(`${this.config.voicevoxUrl}/synthesis?speaker=${t}`,{method:"POST",headers:{Accept:"audio/wav","Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.body)return null;const o=n.body.getReader(),a=[];for(;;){const{done:y,value:x}=await o.read();if(y)break;a.push(x)}const d=a.reduce((y,x)=>y+x.length,0),p=new Uint8Array(d);let g=0;for(const y of a)p.set(y,g),g+=y.length;return p.buffer}async getAudio(e,t){return this.getAudioBuffer(e,t).then(s=>s?Gr(s):null)}async getVoices(){return(await fetch(`${this.config.voicevoxUrl}/speakers`).then(t=>t.json())).flatMap(t=>t.styles.map(s=>({id:s.id.toString(),locale:"ja-JP",description:`${t.name} - ${s.name}`})))}}const Kr={debug:!1,authUrl:"https://auth.jok.io",natsUrl:"https://nats.jok.io",storage:new zr},Vr=new er(Kr),Oo={setup(r){if(r.authUrl||r.storage){const e=this.auth.onUserDataUpdate;this.auth=new er({authUrl:r.authUrl??this.auth.url,storage:r.storage??this.storage}),this.auth.onUserDataUpdate=e}(r.natsUrl||r.storage)&&(this.nats=new Ls({natsUrl:r.natsUrl??this.nats.url,auth:this.auth}))},auth:Vr,storage:new zr,tts:new So,nats:new Ls({...Kr,auth:Vr}),crypto:new yi};me.NatsService=Ls,me.VoicevoxTtsService=Po,me.jok=Oo,Object.defineProperty(me,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jokio/sdk",
3
3
  "description": "pure js/ts sdk for building decentralised localfirst web apps. Provides tts ai model integrations, realtime p2p communication & crypto encryptions.",
4
- "version": "0.3.1",
4
+ "version": "0.3.2",
5
5
  "license": "MIT",
6
6
  "main": "dist/jokio.sdk.umd.js",
7
7
  "module": "dist/jokio.sdk.es.js",