@ephia/transcribe-sdk 1.0.1 → 1.0.3

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.
package/README.md CHANGED
@@ -11,7 +11,26 @@ npm install @ephia/transcribe-sdk
11
11
  ## Prérequis
12
12
 
13
13
  - Contexte sécurisé (HTTPS ou localhost) pour l’accès au microphone.
14
- - Fichier **audio-processor.js** : récupérez-le depuis le package (dans `dist/` après build) et servez-le dans les assets statiques de votre app (ex. `public/audio-processor.js`). Par défaut le SDK charge `/audio-processor.js`.
14
+ - Importer les styles du SDK (obligatoire) : `@ephia/transcribe-sdk/dist/styles.css`
15
+ - Fichier **audio-processor.js** (obligatoire) : le SDK charge par défaut `/audio-processor.js`. Vous devez donc servir ce fichier depuis vos assets statiques.
16
+
17
+ ### Installer le worklet `audio-processor.js`
18
+
19
+ Après `npm install`, copiez le worklet depuis `node_modules` vers vos assets statiques.
20
+
21
+ - Vite / CRA / tout projet avec dossier `public/` :
22
+
23
+ ```bash
24
+ cp node_modules/@ephia/transcribe-sdk/dist/audio-processor.js public/audio-processor.js
25
+ ```
26
+
27
+ - Next.js :
28
+
29
+ ```bash
30
+ cp node_modules/@ephia/transcribe-sdk/dist/audio-processor.js public/audio-processor.js
31
+ ```
32
+
33
+ Si vous ne pouvez pas copier de fichier, vous pouvez aussi héberger ce worklet ailleurs et passer `audioProcessorUrl`.
15
34
 
16
35
  ## Utilisation
17
36
 
@@ -38,13 +57,37 @@ function TranscriptDisplay() {
38
57
  }
39
58
  ```
40
59
 
60
+ ### Next.js (App Router)
61
+
62
+ Le bouton utilise le micro, donc il doit être rendu côté client. Dans Next.js, placez-le dans un composant avec :
63
+
64
+ ```tsx
65
+ "use client";
66
+ ```
67
+
41
68
  ## Props principales
42
69
 
43
70
  - **token** (requis) : clé API Ephia.
44
- - **streamingUrlBase** : URL de base WebSocket (défaut : `ws://localhost:8765` ou `NEXT_PUBLIC_WS_URL`).
71
+ - **streamingUrlBase** : URL de base WebSocket (défaut : `NEXT_PUBLIC_WS_URL`, sinon `ws://localhost:8765` sur `localhost`, sinon `wss://api-platform.ephia.app`).
45
72
  - **audioProcessorUrl** : URL du worklet (défaut : `/audio-processor.js`).
46
73
  - **theme**, **variant**, **size** : apparence du bouton.
47
74
 
75
+ ### Exemple “prod” pour le WebSocket
76
+
77
+ ```tsx
78
+ <TranscriptionButton
79
+ token="YOUR_API_TOKEN"
80
+ streamingUrlBase="wss://api-platform.ephia.app"
81
+ />
82
+ ```
83
+
84
+ ## Dépannage (rapide)
85
+
86
+ - **Erreur / 404 sur `/audio-processor.js`** : copiez bien `node_modules/@ephia/transcribe-sdk/dist/audio-processor.js` vers `public/audio-processor.js` (ou passez `audioProcessorUrl`).
87
+ - **Micro bloqué** : utilisez HTTPS (ou `http://localhost`) et acceptez la permission micro dans le navigateur.
88
+ - **WebSocket KO** : vérifiez `streamingUrlBase` (doit être `ws://` en local, `wss://` en prod) et que votre backend expose bien `/api/v2/streaming/live`.
89
+ - **Bouton “sans style”** : vérifiez l’import `@ephia/transcribe-sdk/dist/styles.css`.
90
+
48
91
  ## Licence
49
92
 
50
93
  Propriétaire. Voir le fichier LICENSE fourni avec le package.
package/dist/index.d.mts CHANGED
@@ -64,7 +64,7 @@ interface TranscriptionButtonProps {
64
64
  token: string;
65
65
  /** Pre-built streaming URL (optional). If not set, built from streamingUrlBase + /api/v2/streaming/live. Use when integrating with preset IDs (e.g. platform). */
66
66
  streamingUrl?: string;
67
- /** Base WebSocket URL when streamingUrl is not set (default: env NEXT_PUBLIC_WS_URL or ws://localhost:8765) */
67
+ /** Base WebSocket URL when streamingUrl is not set (default: env NEXT_PUBLIC_WS_URL, else ws://localhost:8765 on localhost, else wss://plateform-api.ephia.app) */
68
68
  streamingUrlBase?: string;
69
69
  /** URL to load the audio worklet (default: /audio-processor.js) */
70
70
  audioProcessorUrl?: string;
package/dist/index.d.ts CHANGED
@@ -64,7 +64,7 @@ interface TranscriptionButtonProps {
64
64
  token: string;
65
65
  /** Pre-built streaming URL (optional). If not set, built from streamingUrlBase + /api/v2/streaming/live. Use when integrating with preset IDs (e.g. platform). */
66
66
  streamingUrl?: string;
67
- /** Base WebSocket URL when streamingUrl is not set (default: env NEXT_PUBLIC_WS_URL or ws://localhost:8765) */
67
+ /** Base WebSocket URL when streamingUrl is not set (default: env NEXT_PUBLIC_WS_URL, else ws://localhost:8765 on localhost, else wss://plateform-api.ephia.app) */
68
68
  streamingUrlBase?: string;
69
69
  /** URL to load the audio worklet (default: /audio-processor.js) */
70
70
  audioProcessorUrl?: string;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var b1="/audio-processor.js";function r1(n){let[f,h]=react.useState(new Map),[I,Y]=react.useState(false),[o1,B]=react.useState(false),[R,S]=react.useState(false),[Q,q]=react.useState(0),[L,G]=react.useState(null),[e1,C]=react.useState(null),[E,r]=react.useState(null),[z,O]=react.useState(null),[T,H]=react.useState([]),[Z,U]=react.useState(null),s=react.useRef(null),d=react.useRef(null),k=react.useRef(null),M=react.useRef(null),N=react.useRef(null),g=react.useRef(null),v=react.useRef(0),W=react.useRef(0),V=react.useRef(0),p=react.useRef(null),b=react.useRef([]),A=react.useRef(false),J=react.useRef(0),F=react.useRef(false),X=Math.ceil(16e3/128*(2e3/1e3)),D=n.audioProcessorUrl??b1,x=react.useCallback((o,t,a)=>{H(e=>[{timestamp:new Date,direction:o,type:t,data:a},...e].slice(0,100));},[]),P=react.useCallback(async()=>{if(!A.current){if(typeof window<"u"&&!window.isSecureContext){C("Microphone access requires a secure context (HTTPS or localhost)."),r("insecure_context");return}try{let o;try{o=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:{ideal:!0},noiseSuppression:{ideal:!0},autoGainControl:{ideal:!0},channelCount:{ideal:1},sampleRate:{ideal:16e3}}});}catch(u){let i=u;i?.name==="NotAllowedError"?(C("Microphone access was denied."),r("microphone_denied")):i?.name==="NotFoundError"?(C("No microphone found."),r("microphone_not_found")):(C(u instanceof Error?u.message:"Could not access microphone."),r("microphone_error"));return}N.current=o;let t=new AudioContext({sampleRate:16e3,latencyHint:"interactive"});d.current=t;try{await t.audioWorklet.addModule(D);}catch{C("Failed to load audio worklet."),r("audio_worklet_error");return}t.state==="suspended"&&await t.resume();let a=t.createMediaStreamSource(o),e=new AudioWorkletNode(t,"audio-processor");k.current=e;let c=t.createGain();c.gain.value=0,M.current=c,e.connect(c),c.connect(t.destination),v.current=Date.now(),e.port.onmessage=u=>{let i=u.data,i1=Date.now();v.current=i1;let g1=1.4,a1=0;for(let _=0;_<i.length;_++){let $=i[_]*g1;a1+=$*$,i[_]=$;}let h1=Math.sqrt(a1/i.length);V.current=h1,p.current===null&&i1-W.current>33&&(p.current=window.setTimeout(()=>{p.current=null,W.current=Date.now(),q(V.current);},33));let t1=new Int16Array(i.length);for(let _=0;_<i.length;_++){let $=Math.max(-1,Math.min(1,i[_]));t1[_]=$*32767;}if(typeof window<"u"&&window.__isRecordingV2){if(Date.now()-J.current<100)return;if(s.current?.readyState!==WebSocket.OPEN){b.current.push(t1),b.current.length>X&&b.current.splice(0,b.current.length-X);return}s.current.send(t1.buffer);}},a.connect(e),g.current=setInterval(()=>{Date.now()-v.current>2e3&&d.current&&d.current.state==="suspended"&&d.current.resume().catch(i=>{console.error("[V2] Audio resume error:",i);});},2e3),A.current=!0;}catch(o){console.error("[V2] Audio init error:",o),C(o instanceof Error?o.message:"Could not initialize audio."),r("unknown");}}},[D]),j=react.useCallback(()=>{if(!n.token){C("Token is required to connect."),r("token_missing");return}if(s.current?.readyState===WebSocket.OPEN||s.current?.readyState===WebSocket.CONNECTING)return;let o=new URL(n.url);o.searchParams.set("token",n.token),L&&o.searchParams.set("session_id",L),n.vadSettings&&Object.entries(n.vadSettings).forEach(([a,e])=>{e!=null&&o.searchParams.set(a,e.toString());});let t=new WebSocket(o.toString());s.current=t,t.onopen=()=>{t.binaryType="arraybuffer",S(true),C(null),r(null),x("in","connection",{status:"open"}),n.customPrompt&&n.customPrompt.trim().length>0&&t.send(JSON.stringify({type:"set_prompt",custom_prompt:n.customPrompt})),A.current||P(),b.current.length>0&&(b.current.forEach(a=>t.send(a.buffer)),b.current=[]);},t.onmessage=a=>{if(typeof a.data=="string"){let e;try{e=JSON.parse(a.data);}catch(c){console.error("[V2] WS message parse error:",c);return}switch(x("in",e.type,e),e.type){case "session_info":G(e.session_id??null);break;case "speech_start":B(true),U(Date.now()),h(c=>{let u=new Map(c);return u.set(e.chunk_id,{id:e.chunk_id,text:"",status:"interim",isMedicalCorrection:false,seq:e.seq??0,timestamp_ms:e.timestamp_ms,session_num:n.currentSessionNum??0}),u});break;case "transcript_interim":h(c=>{let u=c.get(e.chunk_id);if(!u||u.status==="final")return c;let i=new Map(c);return i.set(e.chunk_id,{...u,text:e.text??""}),i});break;case "transcript_final":h(c=>{let u=c.get(e.chunk_id);if(!u)return c;let i=new Map(c);return i.set(e.chunk_id,{...u,text:e.text??"",status:"final",isMedicalCorrection:e.is_medical_correction??false}),i});break;case "final_sync":t.send(JSON.stringify({type:"ack_finish"})),B(false),F.current&&(F.current=false,s.current&&s.current.readyState!==WebSocket.CLOSED&&s.current.close(1e3,"finalized"),s.current=null,G(null),S(false));break}}},t.onclose=a=>{if(S(false),x("in","connection",{status:"closed"}),!a.wasClean||a.code!==1e3){let e=typeof a.reason=="string"?a.reason:"";a.code===1008||/auth/i.test(e)?(C("WebSocket authentication failed."),r("websocket_auth_error")):(C("WebSocket connection error."),r("websocket_error"));}},t.onerror=()=>{C("WebSocket connection error."),r("websocket_error");};},[n.url,n.token,n.vadSettings,n.customPrompt,L,x,P]),w=async()=>{R||j(),A.current||await P(),J.current=Date.now(),typeof window<"u"&&(window.__isRecordingV2=true),U(Date.now()),Y(true),x("out","recording_start",{});},m1=async()=>{typeof window<"u"&&(window.__isRecordingV2=false),g.current&&(clearInterval(g.current),g.current=null),p.current!==null&&(clearTimeout(p.current),p.current=null),Y(false),x("out","end_of_speech",{}),s.current?.readyState===WebSocket.OPEN&&s.current.send(JSON.stringify({type:"end_of_speech"})),F.current=true;},f1=()=>{h(new Map),H([]);};return react.useEffect(()=>{if(typeof window>"u"||!navigator.permissions?.query)return;let o=false;return navigator.permissions.query({name:"microphone"}).then(t=>{o||(O(t.state),t.onchange=()=>{o||O(t.state);});}).catch(()=>{}),()=>{o=true;}},[]),react.useEffect(()=>()=>{typeof window<"u"&&(window.__isRecordingV2=false),g.current&&(clearInterval(g.current),g.current=null),p.current!==null&&(clearTimeout(p.current),p.current=null),s.current&&s.current.readyState!==WebSocket.CLOSED&&s.current.close(1e3,"unmount"),s.current=null,k.current&&(k.current.disconnect(),k.current=null),M.current&&(M.current.disconnect(),M.current=null),d.current&&d.current.state!=="closed"&&(d.current.close(),d.current=null),N.current&&(N.current.getTracks().forEach(o=>o.stop()),N.current=null);},[]),{chunks:react.useMemo(()=>Array.from(f.values()).sort((o,t)=>o.seq-t.seq),[f]),isRecording:I,isProcessing:o1,isConnected:R,volume:Q,error:e1,errorCode:E,permissionState:z,debugMessages:T,startRecording:w,stopRecording:m1,clear:f1,connect:j,sessionId:L,lastSpeechStartTimestamp:Z}}var K=react.createContext(null),u1={chunks:[],isRecording:false,isProcessing:false,isConnected:false,volume:0,lastSpeechStartTimestamp:null,sessionId:null,debugMessages:[],error:null,errorCode:null,permissionState:null,transcriptionErrors:[],startRecording:async()=>{},stopRecording:async()=>{},clear:()=>{},connect:()=>{}};function T1({children:n}){let[f,h]=react.useState(null),I={state:f,setTranscriptionState:h};return jsxRuntime.jsx(K.Provider,{value:I,children:n})}function x1(){let n=react.useContext(K);return !n||n.state===null?u1:n.state}var d1="ws://localhost:8765",L1="M59.3213 28.7734C75.2612 1.95614 109.301 -7.65698 136.823 6.52832C137.578 6.83434 138.322 7.1956 139.047 7.61523L139.501 7.88086C144.144 10.6216 148.298 13.9147 151.913 17.6357C166.809 32.8058 172.361 55.1934 166.241 75.7207C164.482 81.6226 168.511 88.5994 174.501 90.0283C200.416 96.2103 219.784 119.483 219.784 147.25L219.779 148.011C219.372 180.152 193.185 206.083 160.94 206.083C142.144 206.083 125.405 197.271 114.632 183.554C112.308 180.596 107.236 180.432 105.114 183.538C100.085 190.326 96.6337 193.026 90.0381 197.142L89.8887 197.235C89.8809 197.24 89.8728 197.245 89.8672 197.248L89.8428 197.263C89.8327 197.269 89.8226 197.276 89.8125 197.282C89.7836 197.3 89.6675 197.371 89.5527 197.441L88.7256 197.939C80.1333 203.01 70.1347 205.962 59.5 206.079C59.3816 206.08 59.2783 206.081 59.2139 206.081C59.1514 206.081 59.1351 206.081 59.1201 206.081C59.0999 206.081 59.0722 206.082 59.042 206.082C58.9927 206.082 58.9241 206.083 58.8438 206.083C58.7816 206.083 58.726 206.082 58.6797 206.081L58.5615 206.08C58.5715 206.08 58.5827 206.081 58.5947 206.081C58.6176 206.081 58.6464 206.081 58.6797 206.081C58.7155 206.082 58.7513 206.083 58.7871 206.083C58.7376 206.083 58.6937 206.082 58.6572 206.082C58.6208 206.082 58.5898 206.081 58.5664 206.081C58.5579 206.081 58.55 206.08 58.543 206.08C58.5459 206.08 58.5488 206.08 58.5518 206.08C57.4007 206.075 56.2471 206.038 55.0928 205.965C54.8838 205.952 54.6918 205.938 54.5391 205.927H54.5342C54.5212 205.926 54.4802 205.923 54.4326 205.919C54.2048 205.902 53.9777 205.884 53.752 205.864L53.0684 205.801C53.0642 205.8 53.0598 205.8 53.0557 205.8C53.0504 205.799 53.0315 205.797 53.0117 205.795C39.2845 204.44 26.9546 198.373 17.6709 189.281C17.6096 189.221 17.5559 189.169 17.5195 189.133L17.4424 189.058L17.4336 189.048L17.4111 189.025C17.4055 189.02 17.3975 189.013 17.3896 189.005L17.2354 188.852L17.1133 188.73L16.3311 187.927C16.3267 187.922 16.3213 187.917 16.3164 187.912C16.2951 187.89 16.2642 187.857 16.2275 187.818L15.8408 187.408C15.8373 187.405 15.8328 187.4 15.8291 187.396C15.8054 187.371 15.7715 187.335 15.7324 187.293L15.3379 186.865V186.864L15.2686 186.789V186.788C14.8224 186.297 14.387 185.8 13.9629 185.3L13.8213 185.133L13.8154 185.125C13.7495 185.047 13.67 184.953 13.585 184.851L13.3154 184.523C13.3129 184.52 13.3102 184.517 13.3076 184.514C13.2546 184.449 13.2042 184.387 13.1592 184.332V184.331L12.3984 183.375C4.63682 173.409 0.000271139 160.85 0 147.251V147.103C0.00464141 144.442 0.190754 141.771 0.561523 139.11C0.572202 139.033 0.58146 138.966 0.586914 138.929C0.594568 138.876 0.593821 138.878 0.595703 138.865L0.597656 138.853C0.602198 138.821 0.630548 138.619 0.657227 138.442C2.11823 128.738 5.94765 119.813 11.5166 112.286V112.285C11.5185 112.283 11.521 112.279 11.5244 112.274C11.5277 112.27 11.5331 112.263 11.5381 112.256C11.557 112.23 11.5981 112.175 11.6455 112.111L11.6689 112.078C11.7175 112.013 11.7589 111.96 11.7861 111.924C11.7876 111.922 11.7895 111.92 11.791 111.918C17.1161 104.814 23.8339 99.1947 31.3232 95.2383C36.524 92.4836 42.1922 90.4842 48.1719 89.3867L48.7529 89.2822C48.8256 89.2696 48.8868 89.2593 48.9189 89.2539C48.9284 89.2523 48.9377 89.2511 48.9443 89.25C48.9517 89.2488 48.9576 89.2478 48.9619 89.2471L49.0332 89.2354L49.4531 89.1523C53.7392 88.1691 56.4043 83.3055 54.9941 79.0869C49.7142 63.2942 50.2167 44.5298 58.9385 29.4258L59.3213 28.7734ZM130.184 22.8789C110.496 11.7589 85.4808 18.5561 74.1504 38.1777C66.8151 50.8812 67.004 65.864 73.334 77.9668C76.4886 83.9983 77.6606 91.3213 74.2568 97.2158C70.8529 103.11 63.9254 105.757 57.124 106.041C55.4204 106.112 53.7254 106.288 52.0498 106.567C51.9939 106.577 51.9377 106.587 51.8818 106.597C51.8243 106.607 51.7665 106.616 51.709 106.626C47.369 107.378 43.2603 108.807 39.498 110.801C34.2217 113.587 29.4986 117.543 25.7588 122.555C25.7423 122.577 25.7254 122.599 25.709 122.621C25.6788 122.662 25.6482 122.702 25.6182 122.743C21.6987 128.033 19.0149 134.294 17.9922 141.098C17.9777 141.193 17.964 141.29 17.9502 141.386C17.9421 141.443 17.9337 141.5 17.9258 141.557C17.6653 143.423 17.5345 145.297 17.5312 147.164V147.281C17.5314 157.141 20.9911 166.193 26.7617 173.291C26.796 173.333 26.8307 173.376 26.8652 173.418C26.928 173.495 26.9914 173.571 27.0547 173.647C27.1097 173.714 27.1653 173.78 27.2207 173.846C27.255 173.886 27.2898 173.928 27.3242 173.969C27.6222 174.32 27.9265 174.667 28.2373 175.01C28.2533 175.027 28.2701 175.045 28.2861 175.062C28.3779 175.163 28.4706 175.264 28.5635 175.364C28.5869 175.389 28.6113 175.414 28.6348 175.439C28.7263 175.537 28.8185 175.636 28.9111 175.733C28.9284 175.751 28.9456 175.77 28.9629 175.788C29.1492 175.983 29.3377 176.177 29.5283 176.368L29.6191 176.459C29.6653 176.505 29.7124 176.551 29.7588 176.597C29.8118 176.649 29.8646 176.703 29.918 176.755C36.4444 183.149 45.0865 187.394 54.6963 188.343C54.7093 188.344 54.7223 188.345 54.7354 188.347C55.0558 188.378 55.3777 188.406 55.7002 188.43C55.7229 188.431 55.7459 188.433 55.7686 188.435C55.8995 188.444 56.0309 188.453 56.1621 188.461C57.0287 188.516 57.8957 188.544 58.7607 188.544C58.774 188.544 58.7875 188.544 58.8008 188.544C58.8551 188.544 58.9096 188.543 58.9639 188.543C59.0597 188.543 59.1561 188.542 59.252 188.541C66.9707 188.458 74.181 186.257 80.3291 182.491C80.397 182.45 80.4655 182.408 80.5332 182.366C80.5788 182.338 80.6245 182.309 80.6699 182.28C85.3019 179.394 89.4161 175.552 92.6865 170.841C92.7302 170.778 92.7741 170.715 92.8174 170.652C92.8427 170.615 92.8684 170.578 92.8936 170.541C94.8281 167.712 96.419 164.629 97.6074 161.354C99.3661 156.526 100.166 151.512 100.075 146.559C100.266 130.197 106.911 115.388 117.584 104.556C120.604 101.545 123.936 98.8474 127.529 96.5156C128.082 96.157 127.539 96.5078 129.953 95.0293C135.565 91.8714 140.505 87.3735 144.245 81.6768C144.281 81.6235 144.315 81.5691 144.351 81.5156C144.368 81.4895 144.385 81.4627 144.402 81.4365C144.828 80.7868 145.239 80.1213 145.632 79.4404C155.114 63.0199 152.024 42.7918 139.35 29.8965C136.719 27.1798 133.672 24.7773 130.236 22.7891L130.184 22.8789ZM160.977 106.017C157.768 106.017 154.645 106.381 151.646 107.074C133.344 111.299 119.699 127.698 119.699 147.281C119.699 170.07 138.176 188.544 160.969 188.544C162.749 188.544 164.503 188.431 166.224 188.212C166.304 188.202 166.383 188.188 166.463 188.178C167.233 188.075 167.995 187.952 168.751 187.808C187.826 184.172 202.246 167.411 202.246 147.279C202.246 124.491 183.769 106.017 160.977 106.017Z",E1="M130.184 22.8784C110.496 11.7584 85.4808 18.5556 74.1504 38.1772C66.8151 50.8807 67.004 65.8635 73.334 77.9663C76.4886 83.9978 77.6606 91.3208 74.2568 97.2153C70.8529 103.109 63.9255 105.756 57.1241 106.04C55.4205 106.111 53.7255 106.287 52.0499 106.566C51.994 106.576 51.9378 106.586 51.8819 106.596C51.8244 106.606 51.7665 106.615 51.709 106.625C47.369 107.377 43.2604 108.806 39.4981 110.8C34.2218 113.586 29.4987 117.542 25.7589 122.554C25.7424 122.576 25.7254 122.598 25.709 122.62C25.6788 122.661 25.6482 122.701 25.6182 122.742C21.6987 128.032 19.015 134.293 17.9923 141.097C17.9778 141.192 17.964 141.289 17.9502 141.385C17.9421 141.442 17.9337 141.499 17.9258 141.556C17.6653 143.422 17.5345 145.296 17.5312 147.163V147.28C17.5314 157.14 20.9911 166.192 26.7617 173.29C26.796 173.332 26.8307 173.375 26.8652 173.417C26.928 173.494 26.9915 173.57 27.0548 173.646C27.1098 173.713 27.1653 173.779 27.2207 173.845C27.255 173.885 27.2898 173.927 27.3242 173.968C27.6222 174.319 27.9266 174.666 28.2374 175.009C28.2534 175.026 28.2701 175.044 28.2861 175.061C28.3779 175.162 28.4706 175.263 28.5635 175.363C28.5869 175.388 28.6113 175.413 28.6348 175.438C28.7263 175.536 28.8185 175.635 28.9111 175.732C28.9284 175.75 28.9456 175.769 28.9629 175.787C29.1492 175.982 29.3377 176.176 29.5283 176.367L29.6192 176.458C29.6654 176.504 29.7125 176.55 29.7589 176.596C29.8119 176.648 29.8646 176.702 29.918 176.754C36.4444 183.148 45.0865 187.393 54.6964 188.342C54.7094 188.343 54.7224 188.344 54.7355 188.346C55.0559 188.377 55.3777 188.405 55.7002 188.429C55.7229 188.43 55.746 188.432 55.7687 188.434C55.8996 188.443 56.031 188.452 56.1622 188.46C57.0288 188.515 57.8957 188.543 58.7607 188.543C58.774 188.543 58.7875 188.543 58.8008 188.543C58.8551 188.543 58.9097 188.542 58.964 188.542C59.0598 188.542 59.1561 188.541 59.252 188.54C66.9707 188.457 74.1811 186.256 80.3292 182.49C80.3971 182.449 80.4656 182.407 80.5333 182.365C80.5789 182.337 80.6245 182.308 80.6699 182.279C85.3019 179.393 89.4162 175.551 92.6866 170.84C92.7303 170.777 92.7741 170.714 92.8174 170.651C92.8427 170.614 92.8684 170.577 92.8936 170.54C94.8281 167.711 96.4191 164.628 97.6075 161.353C99.3662 156.525 100.166 151.511 100.075 146.558C100.266 130.196 106.911 115.387 117.584 104.555C120.604 101.544 123.936 98.8469 127.529 96.5151C128.082 96.1565 127.539 96.5073 129.953 95.0288C135.565 91.8709 140.505 87.373 144.245 81.6763C144.281 81.623 144.315 81.5686 144.351 81.5151C144.368 81.489 144.385 81.4622 144.402 81.436C144.828 80.7863 145.239 80.1208 145.632 79.4399C155.114 63.0194 152.024 42.7913 139.35 29.896C136.719 27.1793 133.672 24.7768 130.236 22.7886L130.184 22.8784ZM160.977 106.016C157.768 106.016 154.645 106.38 151.646 107.073C133.344 111.298 119.699 127.697 119.699 147.28C119.699 170.069 138.176 188.543 160.969 188.543C162.749 188.543 164.503 188.43 166.224 188.211C166.304 188.201 166.383 188.187 166.463 188.177C167.233 188.074 167.995 187.951 168.751 187.807C187.826 184.171 202.246 167.41 202.246 147.278C202.246 124.49 183.769 106.016 160.977 106.016Z",M1={S:{logoHeightPx:24,barHeightPx:4},M:{logoHeightPx:40,barHeightPx:5},L:{logoHeightPx:56,barHeightPx:6}};function N1(){if(typeof window>"u")return d1;let f=typeof process<"u"&&process.env&&process.env.NEXT_PUBLIC_WS_URL||""||d1;return String(f).replace(/\/$/,"")}function v1({token:n,streamingUrl:f,streamingUrlBase:h,audioProcessorUrl:I="/audio-processor.js",promptPresetName:Y,vadPresetName:o1,onStateChange:B,logoSrc:R="/ephia_logo_light.svg",theme:S="dark",variant:Q="minimal",size:q="M"}){let L=react.useContext(K),[G,e1]=react.useState(0),C=react.useMemo(()=>f||`${h??N1()}/api/v2/streaming/live`,[f,h]),{chunks:E,isRecording:r,isProcessing:z,isConnected:O,volume:T,error:H,errorCode:Z,permissionState:U,debugMessages:s,startRecording:d,stopRecording:k,clear:M,connect:N,sessionId:g,lastSpeechStartTimestamp:v}=r1({url:C,token:n,currentSessionNum:G,audioProcessorUrl:I});react.useEffect(()=>{r&&e1(w=>w+1);},[r]);let W=react.useMemo(()=>E.filter(w=>w.text==="[ERREUR]"),[E]),V=L?.setTranscriptionState??null;react.useEffect(()=>{let w={chunks:E,isRecording:r,isProcessing:z,isConnected:O,volume:T,lastSpeechStartTimestamp:v??null,sessionId:g,debugMessages:s,error:H,errorCode:Z,permissionState:U,transcriptionErrors:W,startRecording:d,stopRecording:k,clear:M,connect:N};B?.(w),V&&V(w);},[E,r,z,O,v,g,s,H,Z,U,W,B,V]);let p=!n,b=S==="light",A=Q==="standard",J=Math.min(1,Math.max(0,T)),F=Math.sqrt(J),s1=R?.includes("ephia_logo_light")?E1:L1,X=b?"#ffffff":"#262626",{logoHeightPx:D,barHeightPx:x}=M1[q],P=Math.round(D*(220/207)),j=R?.includes("ephia_logo");return jsxRuntime.jsxs("div",{className:`ephia-transcribe-root ephia-transcribe-root--${S} ephia-transcribe-size--${q}`,children:[jsxRuntime.jsxs("div",{className:`ephia-transcribe-poweredby ephia-transcribe-poweredby--${S}`,"aria-hidden":true,children:[jsxRuntime.jsx("button",{type:"button",className:"ephia-transcribe-poweredby-btn",tabIndex:-1,children:"i"}),jsxRuntime.jsx("div",{className:"ephia-transcribe-poweredby-tooltip",children:"Powered by EPHIA"})]}),r&&jsxRuntime.jsx("div",{className:"ephia-transcribe-ring",style:{transform:`scale(${1.02+T*.05})`,boxShadow:`0 0 ${15+T*35}px rgba(239, 68, 68, ${.3+T*.7})`}}),jsxRuntime.jsx("button",{type:"button",onClick:r?k:d,disabled:p,className:"ephia-transcribe-btn",style:{transform:r?`scale(${1.02+T*.1})`:void 0},children:j?jsxRuntime.jsx("svg",{viewBox:"0 0 220 207",className:`ephia-transcribe-logo-svg ${r?"ephia-transcribe-logo-svg--recording":""}`,style:{height:D,width:P},fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":true,children:jsxRuntime.jsx("path",{d:s1,fill:X})}):jsxRuntime.jsx("img",{src:R,alt:"Ephia",className:`ephia-transcribe-logo-img ephia-transcribe-logo-img--${S} ${r?"ephia-transcribe-logo-img--recording":""}`,style:{height:D,width:P}})}),A&&jsxRuntime.jsx("div",{className:`ephia-transcribe-bar-wrap ephia-transcribe-bar-wrap--${S}`,style:{width:P,height:x},title:"Intensit\xE9 vocale",children:jsxRuntime.jsx("div",{className:"ephia-transcribe-bar-fill",style:{width:`${r?Math.round(F*100):0}%`}})})]})}
2
- exports.TranscriptionButton=v1;exports.TranscriptionProvider=T1;exports.useStreamingV2=r1;exports.useTranscription=x1;
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var b1="/audio-processor.js";function r1(t){let[d,g]=react.useState(new Map),[L,Y]=react.useState(false),[o1,I]=react.useState(false),[R,S]=react.useState(false),[Q,q]=react.useState(0),[E,G]=react.useState(null),[e1,C]=react.useState(null),[M,r]=react.useState(null),[z,O]=react.useState(null),[T,U]=react.useState([]),[Z,H]=react.useState(null),s=react.useRef(null),p=react.useRef(null),k=react.useRef(null),N=react.useRef(null),v=react.useRef(null),h=react.useRef(null),V=react.useRef(0),W=react.useRef(0),A=react.useRef(0),m=react.useRef(null),b=react.useRef([]),D=react.useRef(false),J=react.useRef(0),F=react.useRef(false),X=Math.ceil(16e3/128*(2e3/1e3)),B=t.audioProcessorUrl??b1,x=react.useCallback((o,n,a)=>{U(e=>[{timestamp:new Date,direction:o,type:n,data:a},...e].slice(0,100));},[]),P=react.useCallback(async()=>{if(!D.current){if(typeof window<"u"&&!window.isSecureContext){C("Microphone access requires a secure context (HTTPS or localhost)."),r("insecure_context");return}try{let o;try{o=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:{ideal:!0},noiseSuppression:{ideal:!0},autoGainControl:{ideal:!0},channelCount:{ideal:1},sampleRate:{ideal:16e3}}});}catch(u){let i=u;i?.name==="NotAllowedError"?(C("Microphone access was denied."),r("microphone_denied")):i?.name==="NotFoundError"?(C("No microphone found."),r("microphone_not_found")):(C(u instanceof Error?u.message:"Could not access microphone."),r("microphone_error"));return}v.current=o;let n=new AudioContext({sampleRate:16e3,latencyHint:"interactive"});p.current=n;try{await n.audioWorklet.addModule(B);}catch{C("Failed to load audio worklet."),r("audio_worklet_error");return}n.state==="suspended"&&await n.resume();let a=n.createMediaStreamSource(o),e=new AudioWorkletNode(n,"audio-processor");k.current=e;let c=n.createGain();c.gain.value=0,N.current=c,e.connect(c),c.connect(n.destination),V.current=Date.now(),e.port.onmessage=u=>{let i=u.data,i1=Date.now();V.current=i1;let g1=1.4,a1=0;for(let _=0;_<i.length;_++){let $=i[_]*g1;a1+=$*$,i[_]=$;}let h1=Math.sqrt(a1/i.length);A.current=h1,m.current===null&&i1-W.current>33&&(m.current=window.setTimeout(()=>{m.current=null,W.current=Date.now(),q(A.current);},33));let t1=new Int16Array(i.length);for(let _=0;_<i.length;_++){let $=Math.max(-1,Math.min(1,i[_]));t1[_]=$*32767;}if(typeof window<"u"&&window.__isRecordingV2){if(Date.now()-J.current<100)return;if(s.current?.readyState!==WebSocket.OPEN){b.current.push(t1),b.current.length>X&&b.current.splice(0,b.current.length-X);return}s.current.send(t1.buffer);}},a.connect(e),h.current=setInterval(()=>{Date.now()-V.current>2e3&&p.current&&p.current.state==="suspended"&&p.current.resume().catch(i=>{console.error("[V2] Audio resume error:",i);});},2e3),D.current=!0;}catch(o){console.error("[V2] Audio init error:",o),C(o instanceof Error?o.message:"Could not initialize audio."),r("unknown");}}},[B]),j=react.useCallback(()=>{if(!t.token){C("Token is required to connect."),r("token_missing");return}if(s.current?.readyState===WebSocket.OPEN||s.current?.readyState===WebSocket.CONNECTING)return;let o=new URL(t.url);o.searchParams.set("token",t.token),E&&o.searchParams.set("session_id",E),t.vadSettings&&Object.entries(t.vadSettings).forEach(([a,e])=>{e!=null&&o.searchParams.set(a,e.toString());});let n=new WebSocket(o.toString());s.current=n,n.onopen=()=>{n.binaryType="arraybuffer",S(true),C(null),r(null),x("in","connection",{status:"open"}),t.customPrompt&&t.customPrompt.trim().length>0&&n.send(JSON.stringify({type:"set_prompt",custom_prompt:t.customPrompt})),D.current||P(),b.current.length>0&&(b.current.forEach(a=>n.send(a.buffer)),b.current=[]);},n.onmessage=a=>{if(typeof a.data=="string"){let e;try{e=JSON.parse(a.data);}catch(c){console.error("[V2] WS message parse error:",c);return}switch(x("in",e.type,e),e.type){case "session_info":G(e.session_id??null);break;case "speech_start":I(true),H(Date.now()),g(c=>{let u=new Map(c);return u.set(e.chunk_id,{id:e.chunk_id,text:"",status:"interim",isMedicalCorrection:false,seq:e.seq??0,timestamp_ms:e.timestamp_ms,session_num:t.currentSessionNum??0}),u});break;case "transcript_interim":g(c=>{let u=c.get(e.chunk_id);if(!u||u.status==="final")return c;let i=new Map(c);return i.set(e.chunk_id,{...u,text:e.text??""}),i});break;case "transcript_final":g(c=>{let u=c.get(e.chunk_id);if(!u)return c;let i=new Map(c);return i.set(e.chunk_id,{...u,text:e.text??"",status:"final",isMedicalCorrection:e.is_medical_correction??false}),i});break;case "final_sync":n.send(JSON.stringify({type:"ack_finish"})),I(false),F.current&&(F.current=false,s.current&&s.current.readyState!==WebSocket.CLOSED&&s.current.close(1e3,"finalized"),s.current=null,G(null),S(false));break}}},n.onclose=a=>{if(S(false),x("in","connection",{status:"closed"}),!a.wasClean||a.code!==1e3){let e=typeof a.reason=="string"?a.reason:"";a.code===1008||/auth/i.test(e)?(C("WebSocket authentication failed."),r("websocket_auth_error")):(C("WebSocket connection error."),r("websocket_error"));}},n.onerror=()=>{C("WebSocket connection error."),r("websocket_error");};},[t.url,t.token,t.vadSettings,t.customPrompt,E,x,P]),w=async()=>{R||j(),D.current||await P(),J.current=Date.now(),typeof window<"u"&&(window.__isRecordingV2=true),H(Date.now()),Y(true),x("out","recording_start",{});},m1=async()=>{typeof window<"u"&&(window.__isRecordingV2=false),h.current&&(clearInterval(h.current),h.current=null),m.current!==null&&(clearTimeout(m.current),m.current=null),Y(false),x("out","end_of_speech",{}),s.current?.readyState===WebSocket.OPEN&&s.current.send(JSON.stringify({type:"end_of_speech"})),F.current=true;},f1=()=>{g(new Map),U([]);};return react.useEffect(()=>{if(typeof window>"u"||!navigator.permissions?.query)return;let o=false;return navigator.permissions.query({name:"microphone"}).then(n=>{o||(O(n.state),n.onchange=()=>{o||O(n.state);});}).catch(()=>{}),()=>{o=true;}},[]),react.useEffect(()=>()=>{typeof window<"u"&&(window.__isRecordingV2=false),h.current&&(clearInterval(h.current),h.current=null),m.current!==null&&(clearTimeout(m.current),m.current=null),s.current&&s.current.readyState!==WebSocket.CLOSED&&s.current.close(1e3,"unmount"),s.current=null,k.current&&(k.current.disconnect(),k.current=null),N.current&&(N.current.disconnect(),N.current=null),p.current&&p.current.state!=="closed"&&(p.current.close(),p.current=null),v.current&&(v.current.getTracks().forEach(o=>o.stop()),v.current=null);},[]),{chunks:react.useMemo(()=>Array.from(d.values()).sort((o,n)=>o.seq-n.seq),[d]),isRecording:L,isProcessing:o1,isConnected:R,volume:Q,error:e1,errorCode:M,permissionState:z,debugMessages:T,startRecording:w,stopRecording:m1,clear:f1,connect:j,sessionId:E,lastSpeechStartTimestamp:Z}}var K=react.createContext(null),u1={chunks:[],isRecording:false,isProcessing:false,isConnected:false,volume:0,lastSpeechStartTimestamp:null,sessionId:null,debugMessages:[],error:null,errorCode:null,permissionState:null,transcriptionErrors:[],startRecording:async()=>{},stopRecording:async()=>{},clear:()=>{},connect:()=>{}};function T1({children:t}){let[d,g]=react.useState(null),L={state:d,setTranscriptionState:g};return jsxRuntime.jsx(K.Provider,{value:L,children:t})}function x1(){let t=react.useContext(K);return !t||t.state===null?u1:t.state}var R1="ws://localhost:8765",d1="wss://plateform-api.ephia.app",E1="M59.3213 28.7734C75.2612 1.95614 109.301 -7.65698 136.823 6.52832C137.578 6.83434 138.322 7.1956 139.047 7.61523L139.501 7.88086C144.144 10.6216 148.298 13.9147 151.913 17.6357C166.809 32.8058 172.361 55.1934 166.241 75.7207C164.482 81.6226 168.511 88.5994 174.501 90.0283C200.416 96.2103 219.784 119.483 219.784 147.25L219.779 148.011C219.372 180.152 193.185 206.083 160.94 206.083C142.144 206.083 125.405 197.271 114.632 183.554C112.308 180.596 107.236 180.432 105.114 183.538C100.085 190.326 96.6337 193.026 90.0381 197.142L89.8887 197.235C89.8809 197.24 89.8728 197.245 89.8672 197.248L89.8428 197.263C89.8327 197.269 89.8226 197.276 89.8125 197.282C89.7836 197.3 89.6675 197.371 89.5527 197.441L88.7256 197.939C80.1333 203.01 70.1347 205.962 59.5 206.079C59.3816 206.08 59.2783 206.081 59.2139 206.081C59.1514 206.081 59.1351 206.081 59.1201 206.081C59.0999 206.081 59.0722 206.082 59.042 206.082C58.9927 206.082 58.9241 206.083 58.8438 206.083C58.7816 206.083 58.726 206.082 58.6797 206.081L58.5615 206.08C58.5715 206.08 58.5827 206.081 58.5947 206.081C58.6176 206.081 58.6464 206.081 58.6797 206.081C58.7155 206.082 58.7513 206.083 58.7871 206.083C58.7376 206.083 58.6937 206.082 58.6572 206.082C58.6208 206.082 58.5898 206.081 58.5664 206.081C58.5579 206.081 58.55 206.08 58.543 206.08C58.5459 206.08 58.5488 206.08 58.5518 206.08C57.4007 206.075 56.2471 206.038 55.0928 205.965C54.8838 205.952 54.6918 205.938 54.5391 205.927H54.5342C54.5212 205.926 54.4802 205.923 54.4326 205.919C54.2048 205.902 53.9777 205.884 53.752 205.864L53.0684 205.801C53.0642 205.8 53.0598 205.8 53.0557 205.8C53.0504 205.799 53.0315 205.797 53.0117 205.795C39.2845 204.44 26.9546 198.373 17.6709 189.281C17.6096 189.221 17.5559 189.169 17.5195 189.133L17.4424 189.058L17.4336 189.048L17.4111 189.025C17.4055 189.02 17.3975 189.013 17.3896 189.005L17.2354 188.852L17.1133 188.73L16.3311 187.927C16.3267 187.922 16.3213 187.917 16.3164 187.912C16.2951 187.89 16.2642 187.857 16.2275 187.818L15.8408 187.408C15.8373 187.405 15.8328 187.4 15.8291 187.396C15.8054 187.371 15.7715 187.335 15.7324 187.293L15.3379 186.865V186.864L15.2686 186.789V186.788C14.8224 186.297 14.387 185.8 13.9629 185.3L13.8213 185.133L13.8154 185.125C13.7495 185.047 13.67 184.953 13.585 184.851L13.3154 184.523C13.3129 184.52 13.3102 184.517 13.3076 184.514C13.2546 184.449 13.2042 184.387 13.1592 184.332V184.331L12.3984 183.375C4.63682 173.409 0.000271139 160.85 0 147.251V147.103C0.00464141 144.442 0.190754 141.771 0.561523 139.11C0.572202 139.033 0.58146 138.966 0.586914 138.929C0.594568 138.876 0.593821 138.878 0.595703 138.865L0.597656 138.853C0.602198 138.821 0.630548 138.619 0.657227 138.442C2.11823 128.738 5.94765 119.813 11.5166 112.286V112.285C11.5185 112.283 11.521 112.279 11.5244 112.274C11.5277 112.27 11.5331 112.263 11.5381 112.256C11.557 112.23 11.5981 112.175 11.6455 112.111L11.6689 112.078C11.7175 112.013 11.7589 111.96 11.7861 111.924C11.7876 111.922 11.7895 111.92 11.791 111.918C17.1161 104.814 23.8339 99.1947 31.3232 95.2383C36.524 92.4836 42.1922 90.4842 48.1719 89.3867L48.7529 89.2822C48.8256 89.2696 48.8868 89.2593 48.9189 89.2539C48.9284 89.2523 48.9377 89.2511 48.9443 89.25C48.9517 89.2488 48.9576 89.2478 48.9619 89.2471L49.0332 89.2354L49.4531 89.1523C53.7392 88.1691 56.4043 83.3055 54.9941 79.0869C49.7142 63.2942 50.2167 44.5298 58.9385 29.4258L59.3213 28.7734ZM130.184 22.8789C110.496 11.7589 85.4808 18.5561 74.1504 38.1777C66.8151 50.8812 67.004 65.864 73.334 77.9668C76.4886 83.9983 77.6606 91.3213 74.2568 97.2158C70.8529 103.11 63.9254 105.757 57.124 106.041C55.4204 106.112 53.7254 106.288 52.0498 106.567C51.9939 106.577 51.9377 106.587 51.8818 106.597C51.8243 106.607 51.7665 106.616 51.709 106.626C47.369 107.378 43.2603 108.807 39.498 110.801C34.2217 113.587 29.4986 117.543 25.7588 122.555C25.7423 122.577 25.7254 122.599 25.709 122.621C25.6788 122.662 25.6482 122.702 25.6182 122.743C21.6987 128.033 19.0149 134.294 17.9922 141.098C17.9777 141.193 17.964 141.29 17.9502 141.386C17.9421 141.443 17.9337 141.5 17.9258 141.557C17.6653 143.423 17.5345 145.297 17.5312 147.164V147.281C17.5314 157.141 20.9911 166.193 26.7617 173.291C26.796 173.333 26.8307 173.376 26.8652 173.418C26.928 173.495 26.9914 173.571 27.0547 173.647C27.1097 173.714 27.1653 173.78 27.2207 173.846C27.255 173.886 27.2898 173.928 27.3242 173.969C27.6222 174.32 27.9265 174.667 28.2373 175.01C28.2533 175.027 28.2701 175.045 28.2861 175.062C28.3779 175.163 28.4706 175.264 28.5635 175.364C28.5869 175.389 28.6113 175.414 28.6348 175.439C28.7263 175.537 28.8185 175.636 28.9111 175.733C28.9284 175.751 28.9456 175.77 28.9629 175.788C29.1492 175.983 29.3377 176.177 29.5283 176.368L29.6191 176.459C29.6653 176.505 29.7124 176.551 29.7588 176.597C29.8118 176.649 29.8646 176.703 29.918 176.755C36.4444 183.149 45.0865 187.394 54.6963 188.343C54.7093 188.344 54.7223 188.345 54.7354 188.347C55.0558 188.378 55.3777 188.406 55.7002 188.43C55.7229 188.431 55.7459 188.433 55.7686 188.435C55.8995 188.444 56.0309 188.453 56.1621 188.461C57.0287 188.516 57.8957 188.544 58.7607 188.544C58.774 188.544 58.7875 188.544 58.8008 188.544C58.8551 188.544 58.9096 188.543 58.9639 188.543C59.0597 188.543 59.1561 188.542 59.252 188.541C66.9707 188.458 74.181 186.257 80.3291 182.491C80.397 182.45 80.4655 182.408 80.5332 182.366C80.5788 182.338 80.6245 182.309 80.6699 182.28C85.3019 179.394 89.4161 175.552 92.6865 170.841C92.7302 170.778 92.7741 170.715 92.8174 170.652C92.8427 170.615 92.8684 170.578 92.8936 170.541C94.8281 167.712 96.419 164.629 97.6074 161.354C99.3661 156.526 100.166 151.512 100.075 146.559C100.266 130.197 106.911 115.388 117.584 104.556C120.604 101.545 123.936 98.8474 127.529 96.5156C128.082 96.157 127.539 96.5078 129.953 95.0293C135.565 91.8714 140.505 87.3735 144.245 81.6768C144.281 81.6235 144.315 81.5691 144.351 81.5156C144.368 81.4895 144.385 81.4627 144.402 81.4365C144.828 80.7868 145.239 80.1213 145.632 79.4404C155.114 63.0199 152.024 42.7918 139.35 29.8965C136.719 27.1798 133.672 24.7773 130.236 22.7891L130.184 22.8789ZM160.977 106.017C157.768 106.017 154.645 106.381 151.646 107.074C133.344 111.299 119.699 127.698 119.699 147.281C119.699 170.07 138.176 188.544 160.969 188.544C162.749 188.544 164.503 188.431 166.224 188.212C166.304 188.202 166.383 188.188 166.463 188.178C167.233 188.075 167.995 187.952 168.751 187.808C187.826 184.172 202.246 167.411 202.246 147.279C202.246 124.491 183.769 106.017 160.977 106.017Z",M1="M130.184 22.8784C110.496 11.7584 85.4808 18.5556 74.1504 38.1772C66.8151 50.8807 67.004 65.8635 73.334 77.9663C76.4886 83.9978 77.6606 91.3208 74.2568 97.2153C70.8529 103.109 63.9255 105.756 57.1241 106.04C55.4205 106.111 53.7255 106.287 52.0499 106.566C51.994 106.576 51.9378 106.586 51.8819 106.596C51.8244 106.606 51.7665 106.615 51.709 106.625C47.369 107.377 43.2604 108.806 39.4981 110.8C34.2218 113.586 29.4987 117.542 25.7589 122.554C25.7424 122.576 25.7254 122.598 25.709 122.62C25.6788 122.661 25.6482 122.701 25.6182 122.742C21.6987 128.032 19.015 134.293 17.9923 141.097C17.9778 141.192 17.964 141.289 17.9502 141.385C17.9421 141.442 17.9337 141.499 17.9258 141.556C17.6653 143.422 17.5345 145.296 17.5312 147.163V147.28C17.5314 157.14 20.9911 166.192 26.7617 173.29C26.796 173.332 26.8307 173.375 26.8652 173.417C26.928 173.494 26.9915 173.57 27.0548 173.646C27.1098 173.713 27.1653 173.779 27.2207 173.845C27.255 173.885 27.2898 173.927 27.3242 173.968C27.6222 174.319 27.9266 174.666 28.2374 175.009C28.2534 175.026 28.2701 175.044 28.2861 175.061C28.3779 175.162 28.4706 175.263 28.5635 175.363C28.5869 175.388 28.6113 175.413 28.6348 175.438C28.7263 175.536 28.8185 175.635 28.9111 175.732C28.9284 175.75 28.9456 175.769 28.9629 175.787C29.1492 175.982 29.3377 176.176 29.5283 176.367L29.6192 176.458C29.6654 176.504 29.7125 176.55 29.7589 176.596C29.8119 176.648 29.8646 176.702 29.918 176.754C36.4444 183.148 45.0865 187.393 54.6964 188.342C54.7094 188.343 54.7224 188.344 54.7355 188.346C55.0559 188.377 55.3777 188.405 55.7002 188.429C55.7229 188.43 55.746 188.432 55.7687 188.434C55.8996 188.443 56.031 188.452 56.1622 188.46C57.0288 188.515 57.8957 188.543 58.7607 188.543C58.774 188.543 58.7875 188.543 58.8008 188.543C58.8551 188.543 58.9097 188.542 58.964 188.542C59.0598 188.542 59.1561 188.541 59.252 188.54C66.9707 188.457 74.1811 186.256 80.3292 182.49C80.3971 182.449 80.4656 182.407 80.5333 182.365C80.5789 182.337 80.6245 182.308 80.6699 182.279C85.3019 179.393 89.4162 175.551 92.6866 170.84C92.7303 170.777 92.7741 170.714 92.8174 170.651C92.8427 170.614 92.8684 170.577 92.8936 170.54C94.8281 167.711 96.4191 164.628 97.6075 161.353C99.3662 156.525 100.166 151.511 100.075 146.558C100.266 130.196 106.911 115.387 117.584 104.555C120.604 101.544 123.936 98.8469 127.529 96.5151C128.082 96.1565 127.539 96.5073 129.953 95.0288C135.565 91.8709 140.505 87.373 144.245 81.6763C144.281 81.623 144.315 81.5686 144.351 81.5151C144.368 81.489 144.385 81.4622 144.402 81.436C144.828 80.7863 145.239 80.1208 145.632 79.4399C155.114 63.0194 152.024 42.7913 139.35 29.896C136.719 27.1793 133.672 24.7768 130.236 22.7886L130.184 22.8784ZM160.977 106.016C157.768 106.016 154.645 106.38 151.646 107.073C133.344 111.298 119.699 127.697 119.699 147.28C119.699 170.069 138.176 188.543 160.969 188.543C162.749 188.543 164.503 188.43 166.224 188.211C166.304 188.201 166.383 188.187 166.463 188.177C167.233 188.074 167.995 187.951 168.751 187.807C187.826 184.171 202.246 167.41 202.246 147.278C202.246 124.49 183.769 106.016 160.977 106.016Z",N1={S:{logoHeightPx:24,barHeightPx:4},M:{logoHeightPx:40,barHeightPx:5},L:{logoHeightPx:56,barHeightPx:6}};function v1(){let t=typeof process<"u"&&process.env&&process.env.NEXT_PUBLIC_WS_URL||"";if(t)return String(t).replace(/\/$/,"");if(typeof window>"u")return d1;let d=window.location?.hostname??"";return String(d==="localhost"||d==="127.0.0.1"?R1:d1).replace(/\/$/,"")}function V1({token:t,streamingUrl:d,streamingUrlBase:g,audioProcessorUrl:L="/audio-processor.js",promptPresetName:Y,vadPresetName:o1,onStateChange:I,logoSrc:R="/ephia_logo_light.svg",theme:S="dark",variant:Q="minimal",size:q="M"}){let E=react.useContext(K),[G,e1]=react.useState(0),C=react.useMemo(()=>d||`${g??v1()}/api/v2/streaming/live`,[d,g]),{chunks:M,isRecording:r,isProcessing:z,isConnected:O,volume:T,error:U,errorCode:Z,permissionState:H,debugMessages:s,startRecording:p,stopRecording:k,clear:N,connect:v,sessionId:h,lastSpeechStartTimestamp:V}=r1({url:C,token:t,currentSessionNum:G,audioProcessorUrl:L});react.useEffect(()=>{r&&e1(w=>w+1);},[r]);let W=react.useMemo(()=>M.filter(w=>w.text==="[ERREUR]"),[M]),A=E?.setTranscriptionState??null;react.useEffect(()=>{let w={chunks:M,isRecording:r,isProcessing:z,isConnected:O,volume:T,lastSpeechStartTimestamp:V??null,sessionId:h,debugMessages:s,error:U,errorCode:Z,permissionState:H,transcriptionErrors:W,startRecording:p,stopRecording:k,clear:N,connect:v};I?.(w),A&&A(w);},[M,r,z,O,V,h,s,U,Z,H,W,I,A]);let m=!t,b=S==="light",D=Q==="standard",J=Math.min(1,Math.max(0,T)),F=Math.sqrt(J),s1=R?.includes("ephia_logo_light")?M1:E1,X=b?"#ffffff":"#262626",{logoHeightPx:B,barHeightPx:x}=N1[q],P=Math.round(B*(220/207)),j=R?.includes("ephia_logo");return jsxRuntime.jsxs("div",{className:`ephia-transcribe-root ephia-transcribe-root--${S} ephia-transcribe-size--${q}`,children:[jsxRuntime.jsxs("div",{className:`ephia-transcribe-poweredby ephia-transcribe-poweredby--${S}`,"aria-hidden":true,children:[jsxRuntime.jsx("button",{type:"button",className:"ephia-transcribe-poweredby-btn",tabIndex:-1,children:"i"}),jsxRuntime.jsx("div",{className:"ephia-transcribe-poweredby-tooltip",children:"Powered by EPHIA"})]}),r&&jsxRuntime.jsx("div",{className:"ephia-transcribe-ring",style:{transform:`scale(${1.02+T*.05})`,boxShadow:`0 0 ${15+T*35}px rgba(239, 68, 68, ${.3+T*.7})`}}),jsxRuntime.jsx("button",{type:"button",onClick:r?k:p,disabled:m,className:"ephia-transcribe-btn",style:{transform:r?`scale(${1.02+T*.1})`:void 0},children:j?jsxRuntime.jsx("svg",{viewBox:"0 0 220 207",className:`ephia-transcribe-logo-svg ${r?"ephia-transcribe-logo-svg--recording":""}`,style:{height:B,width:P},fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":true,children:jsxRuntime.jsx("path",{d:s1,fill:X})}):jsxRuntime.jsx("img",{src:R,alt:"Ephia",className:`ephia-transcribe-logo-img ephia-transcribe-logo-img--${S} ${r?"ephia-transcribe-logo-img--recording":""}`,style:{height:B,width:P}})}),D&&jsxRuntime.jsx("div",{className:`ephia-transcribe-bar-wrap ephia-transcribe-bar-wrap--${S}`,style:{width:P,height:x},title:"Intensit\xE9 vocale",children:jsxRuntime.jsx("div",{className:"ephia-transcribe-bar-fill",style:{width:`${r?Math.round(F*100):0}%`}})})]})}
2
+ exports.TranscriptionButton=V1;exports.TranscriptionProvider=T1;exports.useStreamingV2=r1;exports.useTranscription=x1;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {createContext,useState,useRef,useCallback,useEffect,useMemo,useContext}from'react';import {jsx,jsxs}from'react/jsx-runtime';var b1="/audio-processor.js";function r1(n){let[f,h]=useState(new Map),[I,Y]=useState(false),[o1,B]=useState(false),[R,S]=useState(false),[Q,q]=useState(0),[L,G]=useState(null),[e1,C]=useState(null),[E,r]=useState(null),[z,O]=useState(null),[T,H]=useState([]),[Z,U]=useState(null),s=useRef(null),d=useRef(null),k=useRef(null),M=useRef(null),N=useRef(null),g=useRef(null),v=useRef(0),W=useRef(0),V=useRef(0),p=useRef(null),b=useRef([]),A=useRef(false),J=useRef(0),F=useRef(false),X=Math.ceil(16e3/128*(2e3/1e3)),D=n.audioProcessorUrl??b1,x=useCallback((o,t,a)=>{H(e=>[{timestamp:new Date,direction:o,type:t,data:a},...e].slice(0,100));},[]),P=useCallback(async()=>{if(!A.current){if(typeof window<"u"&&!window.isSecureContext){C("Microphone access requires a secure context (HTTPS or localhost)."),r("insecure_context");return}try{let o;try{o=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:{ideal:!0},noiseSuppression:{ideal:!0},autoGainControl:{ideal:!0},channelCount:{ideal:1},sampleRate:{ideal:16e3}}});}catch(u){let i=u;i?.name==="NotAllowedError"?(C("Microphone access was denied."),r("microphone_denied")):i?.name==="NotFoundError"?(C("No microphone found."),r("microphone_not_found")):(C(u instanceof Error?u.message:"Could not access microphone."),r("microphone_error"));return}N.current=o;let t=new AudioContext({sampleRate:16e3,latencyHint:"interactive"});d.current=t;try{await t.audioWorklet.addModule(D);}catch{C("Failed to load audio worklet."),r("audio_worklet_error");return}t.state==="suspended"&&await t.resume();let a=t.createMediaStreamSource(o),e=new AudioWorkletNode(t,"audio-processor");k.current=e;let c=t.createGain();c.gain.value=0,M.current=c,e.connect(c),c.connect(t.destination),v.current=Date.now(),e.port.onmessage=u=>{let i=u.data,i1=Date.now();v.current=i1;let g1=1.4,a1=0;for(let _=0;_<i.length;_++){let $=i[_]*g1;a1+=$*$,i[_]=$;}let h1=Math.sqrt(a1/i.length);V.current=h1,p.current===null&&i1-W.current>33&&(p.current=window.setTimeout(()=>{p.current=null,W.current=Date.now(),q(V.current);},33));let t1=new Int16Array(i.length);for(let _=0;_<i.length;_++){let $=Math.max(-1,Math.min(1,i[_]));t1[_]=$*32767;}if(typeof window<"u"&&window.__isRecordingV2){if(Date.now()-J.current<100)return;if(s.current?.readyState!==WebSocket.OPEN){b.current.push(t1),b.current.length>X&&b.current.splice(0,b.current.length-X);return}s.current.send(t1.buffer);}},a.connect(e),g.current=setInterval(()=>{Date.now()-v.current>2e3&&d.current&&d.current.state==="suspended"&&d.current.resume().catch(i=>{console.error("[V2] Audio resume error:",i);});},2e3),A.current=!0;}catch(o){console.error("[V2] Audio init error:",o),C(o instanceof Error?o.message:"Could not initialize audio."),r("unknown");}}},[D]),j=useCallback(()=>{if(!n.token){C("Token is required to connect."),r("token_missing");return}if(s.current?.readyState===WebSocket.OPEN||s.current?.readyState===WebSocket.CONNECTING)return;let o=new URL(n.url);o.searchParams.set("token",n.token),L&&o.searchParams.set("session_id",L),n.vadSettings&&Object.entries(n.vadSettings).forEach(([a,e])=>{e!=null&&o.searchParams.set(a,e.toString());});let t=new WebSocket(o.toString());s.current=t,t.onopen=()=>{t.binaryType="arraybuffer",S(true),C(null),r(null),x("in","connection",{status:"open"}),n.customPrompt&&n.customPrompt.trim().length>0&&t.send(JSON.stringify({type:"set_prompt",custom_prompt:n.customPrompt})),A.current||P(),b.current.length>0&&(b.current.forEach(a=>t.send(a.buffer)),b.current=[]);},t.onmessage=a=>{if(typeof a.data=="string"){let e;try{e=JSON.parse(a.data);}catch(c){console.error("[V2] WS message parse error:",c);return}switch(x("in",e.type,e),e.type){case "session_info":G(e.session_id??null);break;case "speech_start":B(true),U(Date.now()),h(c=>{let u=new Map(c);return u.set(e.chunk_id,{id:e.chunk_id,text:"",status:"interim",isMedicalCorrection:false,seq:e.seq??0,timestamp_ms:e.timestamp_ms,session_num:n.currentSessionNum??0}),u});break;case "transcript_interim":h(c=>{let u=c.get(e.chunk_id);if(!u||u.status==="final")return c;let i=new Map(c);return i.set(e.chunk_id,{...u,text:e.text??""}),i});break;case "transcript_final":h(c=>{let u=c.get(e.chunk_id);if(!u)return c;let i=new Map(c);return i.set(e.chunk_id,{...u,text:e.text??"",status:"final",isMedicalCorrection:e.is_medical_correction??false}),i});break;case "final_sync":t.send(JSON.stringify({type:"ack_finish"})),B(false),F.current&&(F.current=false,s.current&&s.current.readyState!==WebSocket.CLOSED&&s.current.close(1e3,"finalized"),s.current=null,G(null),S(false));break}}},t.onclose=a=>{if(S(false),x("in","connection",{status:"closed"}),!a.wasClean||a.code!==1e3){let e=typeof a.reason=="string"?a.reason:"";a.code===1008||/auth/i.test(e)?(C("WebSocket authentication failed."),r("websocket_auth_error")):(C("WebSocket connection error."),r("websocket_error"));}},t.onerror=()=>{C("WebSocket connection error."),r("websocket_error");};},[n.url,n.token,n.vadSettings,n.customPrompt,L,x,P]),w=async()=>{R||j(),A.current||await P(),J.current=Date.now(),typeof window<"u"&&(window.__isRecordingV2=true),U(Date.now()),Y(true),x("out","recording_start",{});},m1=async()=>{typeof window<"u"&&(window.__isRecordingV2=false),g.current&&(clearInterval(g.current),g.current=null),p.current!==null&&(clearTimeout(p.current),p.current=null),Y(false),x("out","end_of_speech",{}),s.current?.readyState===WebSocket.OPEN&&s.current.send(JSON.stringify({type:"end_of_speech"})),F.current=true;},f1=()=>{h(new Map),H([]);};return useEffect(()=>{if(typeof window>"u"||!navigator.permissions?.query)return;let o=false;return navigator.permissions.query({name:"microphone"}).then(t=>{o||(O(t.state),t.onchange=()=>{o||O(t.state);});}).catch(()=>{}),()=>{o=true;}},[]),useEffect(()=>()=>{typeof window<"u"&&(window.__isRecordingV2=false),g.current&&(clearInterval(g.current),g.current=null),p.current!==null&&(clearTimeout(p.current),p.current=null),s.current&&s.current.readyState!==WebSocket.CLOSED&&s.current.close(1e3,"unmount"),s.current=null,k.current&&(k.current.disconnect(),k.current=null),M.current&&(M.current.disconnect(),M.current=null),d.current&&d.current.state!=="closed"&&(d.current.close(),d.current=null),N.current&&(N.current.getTracks().forEach(o=>o.stop()),N.current=null);},[]),{chunks:useMemo(()=>Array.from(f.values()).sort((o,t)=>o.seq-t.seq),[f]),isRecording:I,isProcessing:o1,isConnected:R,volume:Q,error:e1,errorCode:E,permissionState:z,debugMessages:T,startRecording:w,stopRecording:m1,clear:f1,connect:j,sessionId:L,lastSpeechStartTimestamp:Z}}var K=createContext(null),u1={chunks:[],isRecording:false,isProcessing:false,isConnected:false,volume:0,lastSpeechStartTimestamp:null,sessionId:null,debugMessages:[],error:null,errorCode:null,permissionState:null,transcriptionErrors:[],startRecording:async()=>{},stopRecording:async()=>{},clear:()=>{},connect:()=>{}};function T1({children:n}){let[f,h]=useState(null),I={state:f,setTranscriptionState:h};return jsx(K.Provider,{value:I,children:n})}function x1(){let n=useContext(K);return !n||n.state===null?u1:n.state}var d1="ws://localhost:8765",L1="M59.3213 28.7734C75.2612 1.95614 109.301 -7.65698 136.823 6.52832C137.578 6.83434 138.322 7.1956 139.047 7.61523L139.501 7.88086C144.144 10.6216 148.298 13.9147 151.913 17.6357C166.809 32.8058 172.361 55.1934 166.241 75.7207C164.482 81.6226 168.511 88.5994 174.501 90.0283C200.416 96.2103 219.784 119.483 219.784 147.25L219.779 148.011C219.372 180.152 193.185 206.083 160.94 206.083C142.144 206.083 125.405 197.271 114.632 183.554C112.308 180.596 107.236 180.432 105.114 183.538C100.085 190.326 96.6337 193.026 90.0381 197.142L89.8887 197.235C89.8809 197.24 89.8728 197.245 89.8672 197.248L89.8428 197.263C89.8327 197.269 89.8226 197.276 89.8125 197.282C89.7836 197.3 89.6675 197.371 89.5527 197.441L88.7256 197.939C80.1333 203.01 70.1347 205.962 59.5 206.079C59.3816 206.08 59.2783 206.081 59.2139 206.081C59.1514 206.081 59.1351 206.081 59.1201 206.081C59.0999 206.081 59.0722 206.082 59.042 206.082C58.9927 206.082 58.9241 206.083 58.8438 206.083C58.7816 206.083 58.726 206.082 58.6797 206.081L58.5615 206.08C58.5715 206.08 58.5827 206.081 58.5947 206.081C58.6176 206.081 58.6464 206.081 58.6797 206.081C58.7155 206.082 58.7513 206.083 58.7871 206.083C58.7376 206.083 58.6937 206.082 58.6572 206.082C58.6208 206.082 58.5898 206.081 58.5664 206.081C58.5579 206.081 58.55 206.08 58.543 206.08C58.5459 206.08 58.5488 206.08 58.5518 206.08C57.4007 206.075 56.2471 206.038 55.0928 205.965C54.8838 205.952 54.6918 205.938 54.5391 205.927H54.5342C54.5212 205.926 54.4802 205.923 54.4326 205.919C54.2048 205.902 53.9777 205.884 53.752 205.864L53.0684 205.801C53.0642 205.8 53.0598 205.8 53.0557 205.8C53.0504 205.799 53.0315 205.797 53.0117 205.795C39.2845 204.44 26.9546 198.373 17.6709 189.281C17.6096 189.221 17.5559 189.169 17.5195 189.133L17.4424 189.058L17.4336 189.048L17.4111 189.025C17.4055 189.02 17.3975 189.013 17.3896 189.005L17.2354 188.852L17.1133 188.73L16.3311 187.927C16.3267 187.922 16.3213 187.917 16.3164 187.912C16.2951 187.89 16.2642 187.857 16.2275 187.818L15.8408 187.408C15.8373 187.405 15.8328 187.4 15.8291 187.396C15.8054 187.371 15.7715 187.335 15.7324 187.293L15.3379 186.865V186.864L15.2686 186.789V186.788C14.8224 186.297 14.387 185.8 13.9629 185.3L13.8213 185.133L13.8154 185.125C13.7495 185.047 13.67 184.953 13.585 184.851L13.3154 184.523C13.3129 184.52 13.3102 184.517 13.3076 184.514C13.2546 184.449 13.2042 184.387 13.1592 184.332V184.331L12.3984 183.375C4.63682 173.409 0.000271139 160.85 0 147.251V147.103C0.00464141 144.442 0.190754 141.771 0.561523 139.11C0.572202 139.033 0.58146 138.966 0.586914 138.929C0.594568 138.876 0.593821 138.878 0.595703 138.865L0.597656 138.853C0.602198 138.821 0.630548 138.619 0.657227 138.442C2.11823 128.738 5.94765 119.813 11.5166 112.286V112.285C11.5185 112.283 11.521 112.279 11.5244 112.274C11.5277 112.27 11.5331 112.263 11.5381 112.256C11.557 112.23 11.5981 112.175 11.6455 112.111L11.6689 112.078C11.7175 112.013 11.7589 111.96 11.7861 111.924C11.7876 111.922 11.7895 111.92 11.791 111.918C17.1161 104.814 23.8339 99.1947 31.3232 95.2383C36.524 92.4836 42.1922 90.4842 48.1719 89.3867L48.7529 89.2822C48.8256 89.2696 48.8868 89.2593 48.9189 89.2539C48.9284 89.2523 48.9377 89.2511 48.9443 89.25C48.9517 89.2488 48.9576 89.2478 48.9619 89.2471L49.0332 89.2354L49.4531 89.1523C53.7392 88.1691 56.4043 83.3055 54.9941 79.0869C49.7142 63.2942 50.2167 44.5298 58.9385 29.4258L59.3213 28.7734ZM130.184 22.8789C110.496 11.7589 85.4808 18.5561 74.1504 38.1777C66.8151 50.8812 67.004 65.864 73.334 77.9668C76.4886 83.9983 77.6606 91.3213 74.2568 97.2158C70.8529 103.11 63.9254 105.757 57.124 106.041C55.4204 106.112 53.7254 106.288 52.0498 106.567C51.9939 106.577 51.9377 106.587 51.8818 106.597C51.8243 106.607 51.7665 106.616 51.709 106.626C47.369 107.378 43.2603 108.807 39.498 110.801C34.2217 113.587 29.4986 117.543 25.7588 122.555C25.7423 122.577 25.7254 122.599 25.709 122.621C25.6788 122.662 25.6482 122.702 25.6182 122.743C21.6987 128.033 19.0149 134.294 17.9922 141.098C17.9777 141.193 17.964 141.29 17.9502 141.386C17.9421 141.443 17.9337 141.5 17.9258 141.557C17.6653 143.423 17.5345 145.297 17.5312 147.164V147.281C17.5314 157.141 20.9911 166.193 26.7617 173.291C26.796 173.333 26.8307 173.376 26.8652 173.418C26.928 173.495 26.9914 173.571 27.0547 173.647C27.1097 173.714 27.1653 173.78 27.2207 173.846C27.255 173.886 27.2898 173.928 27.3242 173.969C27.6222 174.32 27.9265 174.667 28.2373 175.01C28.2533 175.027 28.2701 175.045 28.2861 175.062C28.3779 175.163 28.4706 175.264 28.5635 175.364C28.5869 175.389 28.6113 175.414 28.6348 175.439C28.7263 175.537 28.8185 175.636 28.9111 175.733C28.9284 175.751 28.9456 175.77 28.9629 175.788C29.1492 175.983 29.3377 176.177 29.5283 176.368L29.6191 176.459C29.6653 176.505 29.7124 176.551 29.7588 176.597C29.8118 176.649 29.8646 176.703 29.918 176.755C36.4444 183.149 45.0865 187.394 54.6963 188.343C54.7093 188.344 54.7223 188.345 54.7354 188.347C55.0558 188.378 55.3777 188.406 55.7002 188.43C55.7229 188.431 55.7459 188.433 55.7686 188.435C55.8995 188.444 56.0309 188.453 56.1621 188.461C57.0287 188.516 57.8957 188.544 58.7607 188.544C58.774 188.544 58.7875 188.544 58.8008 188.544C58.8551 188.544 58.9096 188.543 58.9639 188.543C59.0597 188.543 59.1561 188.542 59.252 188.541C66.9707 188.458 74.181 186.257 80.3291 182.491C80.397 182.45 80.4655 182.408 80.5332 182.366C80.5788 182.338 80.6245 182.309 80.6699 182.28C85.3019 179.394 89.4161 175.552 92.6865 170.841C92.7302 170.778 92.7741 170.715 92.8174 170.652C92.8427 170.615 92.8684 170.578 92.8936 170.541C94.8281 167.712 96.419 164.629 97.6074 161.354C99.3661 156.526 100.166 151.512 100.075 146.559C100.266 130.197 106.911 115.388 117.584 104.556C120.604 101.545 123.936 98.8474 127.529 96.5156C128.082 96.157 127.539 96.5078 129.953 95.0293C135.565 91.8714 140.505 87.3735 144.245 81.6768C144.281 81.6235 144.315 81.5691 144.351 81.5156C144.368 81.4895 144.385 81.4627 144.402 81.4365C144.828 80.7868 145.239 80.1213 145.632 79.4404C155.114 63.0199 152.024 42.7918 139.35 29.8965C136.719 27.1798 133.672 24.7773 130.236 22.7891L130.184 22.8789ZM160.977 106.017C157.768 106.017 154.645 106.381 151.646 107.074C133.344 111.299 119.699 127.698 119.699 147.281C119.699 170.07 138.176 188.544 160.969 188.544C162.749 188.544 164.503 188.431 166.224 188.212C166.304 188.202 166.383 188.188 166.463 188.178C167.233 188.075 167.995 187.952 168.751 187.808C187.826 184.172 202.246 167.411 202.246 147.279C202.246 124.491 183.769 106.017 160.977 106.017Z",E1="M130.184 22.8784C110.496 11.7584 85.4808 18.5556 74.1504 38.1772C66.8151 50.8807 67.004 65.8635 73.334 77.9663C76.4886 83.9978 77.6606 91.3208 74.2568 97.2153C70.8529 103.109 63.9255 105.756 57.1241 106.04C55.4205 106.111 53.7255 106.287 52.0499 106.566C51.994 106.576 51.9378 106.586 51.8819 106.596C51.8244 106.606 51.7665 106.615 51.709 106.625C47.369 107.377 43.2604 108.806 39.4981 110.8C34.2218 113.586 29.4987 117.542 25.7589 122.554C25.7424 122.576 25.7254 122.598 25.709 122.62C25.6788 122.661 25.6482 122.701 25.6182 122.742C21.6987 128.032 19.015 134.293 17.9923 141.097C17.9778 141.192 17.964 141.289 17.9502 141.385C17.9421 141.442 17.9337 141.499 17.9258 141.556C17.6653 143.422 17.5345 145.296 17.5312 147.163V147.28C17.5314 157.14 20.9911 166.192 26.7617 173.29C26.796 173.332 26.8307 173.375 26.8652 173.417C26.928 173.494 26.9915 173.57 27.0548 173.646C27.1098 173.713 27.1653 173.779 27.2207 173.845C27.255 173.885 27.2898 173.927 27.3242 173.968C27.6222 174.319 27.9266 174.666 28.2374 175.009C28.2534 175.026 28.2701 175.044 28.2861 175.061C28.3779 175.162 28.4706 175.263 28.5635 175.363C28.5869 175.388 28.6113 175.413 28.6348 175.438C28.7263 175.536 28.8185 175.635 28.9111 175.732C28.9284 175.75 28.9456 175.769 28.9629 175.787C29.1492 175.982 29.3377 176.176 29.5283 176.367L29.6192 176.458C29.6654 176.504 29.7125 176.55 29.7589 176.596C29.8119 176.648 29.8646 176.702 29.918 176.754C36.4444 183.148 45.0865 187.393 54.6964 188.342C54.7094 188.343 54.7224 188.344 54.7355 188.346C55.0559 188.377 55.3777 188.405 55.7002 188.429C55.7229 188.43 55.746 188.432 55.7687 188.434C55.8996 188.443 56.031 188.452 56.1622 188.46C57.0288 188.515 57.8957 188.543 58.7607 188.543C58.774 188.543 58.7875 188.543 58.8008 188.543C58.8551 188.543 58.9097 188.542 58.964 188.542C59.0598 188.542 59.1561 188.541 59.252 188.54C66.9707 188.457 74.1811 186.256 80.3292 182.49C80.3971 182.449 80.4656 182.407 80.5333 182.365C80.5789 182.337 80.6245 182.308 80.6699 182.279C85.3019 179.393 89.4162 175.551 92.6866 170.84C92.7303 170.777 92.7741 170.714 92.8174 170.651C92.8427 170.614 92.8684 170.577 92.8936 170.54C94.8281 167.711 96.4191 164.628 97.6075 161.353C99.3662 156.525 100.166 151.511 100.075 146.558C100.266 130.196 106.911 115.387 117.584 104.555C120.604 101.544 123.936 98.8469 127.529 96.5151C128.082 96.1565 127.539 96.5073 129.953 95.0288C135.565 91.8709 140.505 87.373 144.245 81.6763C144.281 81.623 144.315 81.5686 144.351 81.5151C144.368 81.489 144.385 81.4622 144.402 81.436C144.828 80.7863 145.239 80.1208 145.632 79.4399C155.114 63.0194 152.024 42.7913 139.35 29.896C136.719 27.1793 133.672 24.7768 130.236 22.7886L130.184 22.8784ZM160.977 106.016C157.768 106.016 154.645 106.38 151.646 107.073C133.344 111.298 119.699 127.697 119.699 147.28C119.699 170.069 138.176 188.543 160.969 188.543C162.749 188.543 164.503 188.43 166.224 188.211C166.304 188.201 166.383 188.187 166.463 188.177C167.233 188.074 167.995 187.951 168.751 187.807C187.826 184.171 202.246 167.41 202.246 147.278C202.246 124.49 183.769 106.016 160.977 106.016Z",M1={S:{logoHeightPx:24,barHeightPx:4},M:{logoHeightPx:40,barHeightPx:5},L:{logoHeightPx:56,barHeightPx:6}};function N1(){if(typeof window>"u")return d1;let f=typeof process<"u"&&process.env&&process.env.NEXT_PUBLIC_WS_URL||""||d1;return String(f).replace(/\/$/,"")}function v1({token:n,streamingUrl:f,streamingUrlBase:h,audioProcessorUrl:I="/audio-processor.js",promptPresetName:Y,vadPresetName:o1,onStateChange:B,logoSrc:R="/ephia_logo_light.svg",theme:S="dark",variant:Q="minimal",size:q="M"}){let L=useContext(K),[G,e1]=useState(0),C=useMemo(()=>f||`${h??N1()}/api/v2/streaming/live`,[f,h]),{chunks:E,isRecording:r,isProcessing:z,isConnected:O,volume:T,error:H,errorCode:Z,permissionState:U,debugMessages:s,startRecording:d,stopRecording:k,clear:M,connect:N,sessionId:g,lastSpeechStartTimestamp:v}=r1({url:C,token:n,currentSessionNum:G,audioProcessorUrl:I});useEffect(()=>{r&&e1(w=>w+1);},[r]);let W=useMemo(()=>E.filter(w=>w.text==="[ERREUR]"),[E]),V=L?.setTranscriptionState??null;useEffect(()=>{let w={chunks:E,isRecording:r,isProcessing:z,isConnected:O,volume:T,lastSpeechStartTimestamp:v??null,sessionId:g,debugMessages:s,error:H,errorCode:Z,permissionState:U,transcriptionErrors:W,startRecording:d,stopRecording:k,clear:M,connect:N};B?.(w),V&&V(w);},[E,r,z,O,v,g,s,H,Z,U,W,B,V]);let p=!n,b=S==="light",A=Q==="standard",J=Math.min(1,Math.max(0,T)),F=Math.sqrt(J),s1=R?.includes("ephia_logo_light")?E1:L1,X=b?"#ffffff":"#262626",{logoHeightPx:D,barHeightPx:x}=M1[q],P=Math.round(D*(220/207)),j=R?.includes("ephia_logo");return jsxs("div",{className:`ephia-transcribe-root ephia-transcribe-root--${S} ephia-transcribe-size--${q}`,children:[jsxs("div",{className:`ephia-transcribe-poweredby ephia-transcribe-poweredby--${S}`,"aria-hidden":true,children:[jsx("button",{type:"button",className:"ephia-transcribe-poweredby-btn",tabIndex:-1,children:"i"}),jsx("div",{className:"ephia-transcribe-poweredby-tooltip",children:"Powered by EPHIA"})]}),r&&jsx("div",{className:"ephia-transcribe-ring",style:{transform:`scale(${1.02+T*.05})`,boxShadow:`0 0 ${15+T*35}px rgba(239, 68, 68, ${.3+T*.7})`}}),jsx("button",{type:"button",onClick:r?k:d,disabled:p,className:"ephia-transcribe-btn",style:{transform:r?`scale(${1.02+T*.1})`:void 0},children:j?jsx("svg",{viewBox:"0 0 220 207",className:`ephia-transcribe-logo-svg ${r?"ephia-transcribe-logo-svg--recording":""}`,style:{height:D,width:P},fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":true,children:jsx("path",{d:s1,fill:X})}):jsx("img",{src:R,alt:"Ephia",className:`ephia-transcribe-logo-img ephia-transcribe-logo-img--${S} ${r?"ephia-transcribe-logo-img--recording":""}`,style:{height:D,width:P}})}),A&&jsx("div",{className:`ephia-transcribe-bar-wrap ephia-transcribe-bar-wrap--${S}`,style:{width:P,height:x},title:"Intensit\xE9 vocale",children:jsx("div",{className:"ephia-transcribe-bar-fill",style:{width:`${r?Math.round(F*100):0}%`}})})]})}
2
- export{v1 as TranscriptionButton,T1 as TranscriptionProvider,r1 as useStreamingV2,x1 as useTranscription};
1
+ import {createContext,useState,useRef,useCallback,useEffect,useMemo,useContext}from'react';import {jsx,jsxs}from'react/jsx-runtime';var b1="/audio-processor.js";function r1(t){let[d,g]=useState(new Map),[L,Y]=useState(false),[o1,I]=useState(false),[R,S]=useState(false),[Q,q]=useState(0),[E,G]=useState(null),[e1,C]=useState(null),[M,r]=useState(null),[z,O]=useState(null),[T,U]=useState([]),[Z,H]=useState(null),s=useRef(null),p=useRef(null),k=useRef(null),N=useRef(null),v=useRef(null),h=useRef(null),V=useRef(0),W=useRef(0),A=useRef(0),m=useRef(null),b=useRef([]),D=useRef(false),J=useRef(0),F=useRef(false),X=Math.ceil(16e3/128*(2e3/1e3)),B=t.audioProcessorUrl??b1,x=useCallback((o,n,a)=>{U(e=>[{timestamp:new Date,direction:o,type:n,data:a},...e].slice(0,100));},[]),P=useCallback(async()=>{if(!D.current){if(typeof window<"u"&&!window.isSecureContext){C("Microphone access requires a secure context (HTTPS or localhost)."),r("insecure_context");return}try{let o;try{o=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:{ideal:!0},noiseSuppression:{ideal:!0},autoGainControl:{ideal:!0},channelCount:{ideal:1},sampleRate:{ideal:16e3}}});}catch(u){let i=u;i?.name==="NotAllowedError"?(C("Microphone access was denied."),r("microphone_denied")):i?.name==="NotFoundError"?(C("No microphone found."),r("microphone_not_found")):(C(u instanceof Error?u.message:"Could not access microphone."),r("microphone_error"));return}v.current=o;let n=new AudioContext({sampleRate:16e3,latencyHint:"interactive"});p.current=n;try{await n.audioWorklet.addModule(B);}catch{C("Failed to load audio worklet."),r("audio_worklet_error");return}n.state==="suspended"&&await n.resume();let a=n.createMediaStreamSource(o),e=new AudioWorkletNode(n,"audio-processor");k.current=e;let c=n.createGain();c.gain.value=0,N.current=c,e.connect(c),c.connect(n.destination),V.current=Date.now(),e.port.onmessage=u=>{let i=u.data,i1=Date.now();V.current=i1;let g1=1.4,a1=0;for(let _=0;_<i.length;_++){let $=i[_]*g1;a1+=$*$,i[_]=$;}let h1=Math.sqrt(a1/i.length);A.current=h1,m.current===null&&i1-W.current>33&&(m.current=window.setTimeout(()=>{m.current=null,W.current=Date.now(),q(A.current);},33));let t1=new Int16Array(i.length);for(let _=0;_<i.length;_++){let $=Math.max(-1,Math.min(1,i[_]));t1[_]=$*32767;}if(typeof window<"u"&&window.__isRecordingV2){if(Date.now()-J.current<100)return;if(s.current?.readyState!==WebSocket.OPEN){b.current.push(t1),b.current.length>X&&b.current.splice(0,b.current.length-X);return}s.current.send(t1.buffer);}},a.connect(e),h.current=setInterval(()=>{Date.now()-V.current>2e3&&p.current&&p.current.state==="suspended"&&p.current.resume().catch(i=>{console.error("[V2] Audio resume error:",i);});},2e3),D.current=!0;}catch(o){console.error("[V2] Audio init error:",o),C(o instanceof Error?o.message:"Could not initialize audio."),r("unknown");}}},[B]),j=useCallback(()=>{if(!t.token){C("Token is required to connect."),r("token_missing");return}if(s.current?.readyState===WebSocket.OPEN||s.current?.readyState===WebSocket.CONNECTING)return;let o=new URL(t.url);o.searchParams.set("token",t.token),E&&o.searchParams.set("session_id",E),t.vadSettings&&Object.entries(t.vadSettings).forEach(([a,e])=>{e!=null&&o.searchParams.set(a,e.toString());});let n=new WebSocket(o.toString());s.current=n,n.onopen=()=>{n.binaryType="arraybuffer",S(true),C(null),r(null),x("in","connection",{status:"open"}),t.customPrompt&&t.customPrompt.trim().length>0&&n.send(JSON.stringify({type:"set_prompt",custom_prompt:t.customPrompt})),D.current||P(),b.current.length>0&&(b.current.forEach(a=>n.send(a.buffer)),b.current=[]);},n.onmessage=a=>{if(typeof a.data=="string"){let e;try{e=JSON.parse(a.data);}catch(c){console.error("[V2] WS message parse error:",c);return}switch(x("in",e.type,e),e.type){case "session_info":G(e.session_id??null);break;case "speech_start":I(true),H(Date.now()),g(c=>{let u=new Map(c);return u.set(e.chunk_id,{id:e.chunk_id,text:"",status:"interim",isMedicalCorrection:false,seq:e.seq??0,timestamp_ms:e.timestamp_ms,session_num:t.currentSessionNum??0}),u});break;case "transcript_interim":g(c=>{let u=c.get(e.chunk_id);if(!u||u.status==="final")return c;let i=new Map(c);return i.set(e.chunk_id,{...u,text:e.text??""}),i});break;case "transcript_final":g(c=>{let u=c.get(e.chunk_id);if(!u)return c;let i=new Map(c);return i.set(e.chunk_id,{...u,text:e.text??"",status:"final",isMedicalCorrection:e.is_medical_correction??false}),i});break;case "final_sync":n.send(JSON.stringify({type:"ack_finish"})),I(false),F.current&&(F.current=false,s.current&&s.current.readyState!==WebSocket.CLOSED&&s.current.close(1e3,"finalized"),s.current=null,G(null),S(false));break}}},n.onclose=a=>{if(S(false),x("in","connection",{status:"closed"}),!a.wasClean||a.code!==1e3){let e=typeof a.reason=="string"?a.reason:"";a.code===1008||/auth/i.test(e)?(C("WebSocket authentication failed."),r("websocket_auth_error")):(C("WebSocket connection error."),r("websocket_error"));}},n.onerror=()=>{C("WebSocket connection error."),r("websocket_error");};},[t.url,t.token,t.vadSettings,t.customPrompt,E,x,P]),w=async()=>{R||j(),D.current||await P(),J.current=Date.now(),typeof window<"u"&&(window.__isRecordingV2=true),H(Date.now()),Y(true),x("out","recording_start",{});},m1=async()=>{typeof window<"u"&&(window.__isRecordingV2=false),h.current&&(clearInterval(h.current),h.current=null),m.current!==null&&(clearTimeout(m.current),m.current=null),Y(false),x("out","end_of_speech",{}),s.current?.readyState===WebSocket.OPEN&&s.current.send(JSON.stringify({type:"end_of_speech"})),F.current=true;},f1=()=>{g(new Map),U([]);};return useEffect(()=>{if(typeof window>"u"||!navigator.permissions?.query)return;let o=false;return navigator.permissions.query({name:"microphone"}).then(n=>{o||(O(n.state),n.onchange=()=>{o||O(n.state);});}).catch(()=>{}),()=>{o=true;}},[]),useEffect(()=>()=>{typeof window<"u"&&(window.__isRecordingV2=false),h.current&&(clearInterval(h.current),h.current=null),m.current!==null&&(clearTimeout(m.current),m.current=null),s.current&&s.current.readyState!==WebSocket.CLOSED&&s.current.close(1e3,"unmount"),s.current=null,k.current&&(k.current.disconnect(),k.current=null),N.current&&(N.current.disconnect(),N.current=null),p.current&&p.current.state!=="closed"&&(p.current.close(),p.current=null),v.current&&(v.current.getTracks().forEach(o=>o.stop()),v.current=null);},[]),{chunks:useMemo(()=>Array.from(d.values()).sort((o,n)=>o.seq-n.seq),[d]),isRecording:L,isProcessing:o1,isConnected:R,volume:Q,error:e1,errorCode:M,permissionState:z,debugMessages:T,startRecording:w,stopRecording:m1,clear:f1,connect:j,sessionId:E,lastSpeechStartTimestamp:Z}}var K=createContext(null),u1={chunks:[],isRecording:false,isProcessing:false,isConnected:false,volume:0,lastSpeechStartTimestamp:null,sessionId:null,debugMessages:[],error:null,errorCode:null,permissionState:null,transcriptionErrors:[],startRecording:async()=>{},stopRecording:async()=>{},clear:()=>{},connect:()=>{}};function T1({children:t}){let[d,g]=useState(null),L={state:d,setTranscriptionState:g};return jsx(K.Provider,{value:L,children:t})}function x1(){let t=useContext(K);return !t||t.state===null?u1:t.state}var R1="ws://localhost:8765",d1="wss://plateform-api.ephia.app",E1="M59.3213 28.7734C75.2612 1.95614 109.301 -7.65698 136.823 6.52832C137.578 6.83434 138.322 7.1956 139.047 7.61523L139.501 7.88086C144.144 10.6216 148.298 13.9147 151.913 17.6357C166.809 32.8058 172.361 55.1934 166.241 75.7207C164.482 81.6226 168.511 88.5994 174.501 90.0283C200.416 96.2103 219.784 119.483 219.784 147.25L219.779 148.011C219.372 180.152 193.185 206.083 160.94 206.083C142.144 206.083 125.405 197.271 114.632 183.554C112.308 180.596 107.236 180.432 105.114 183.538C100.085 190.326 96.6337 193.026 90.0381 197.142L89.8887 197.235C89.8809 197.24 89.8728 197.245 89.8672 197.248L89.8428 197.263C89.8327 197.269 89.8226 197.276 89.8125 197.282C89.7836 197.3 89.6675 197.371 89.5527 197.441L88.7256 197.939C80.1333 203.01 70.1347 205.962 59.5 206.079C59.3816 206.08 59.2783 206.081 59.2139 206.081C59.1514 206.081 59.1351 206.081 59.1201 206.081C59.0999 206.081 59.0722 206.082 59.042 206.082C58.9927 206.082 58.9241 206.083 58.8438 206.083C58.7816 206.083 58.726 206.082 58.6797 206.081L58.5615 206.08C58.5715 206.08 58.5827 206.081 58.5947 206.081C58.6176 206.081 58.6464 206.081 58.6797 206.081C58.7155 206.082 58.7513 206.083 58.7871 206.083C58.7376 206.083 58.6937 206.082 58.6572 206.082C58.6208 206.082 58.5898 206.081 58.5664 206.081C58.5579 206.081 58.55 206.08 58.543 206.08C58.5459 206.08 58.5488 206.08 58.5518 206.08C57.4007 206.075 56.2471 206.038 55.0928 205.965C54.8838 205.952 54.6918 205.938 54.5391 205.927H54.5342C54.5212 205.926 54.4802 205.923 54.4326 205.919C54.2048 205.902 53.9777 205.884 53.752 205.864L53.0684 205.801C53.0642 205.8 53.0598 205.8 53.0557 205.8C53.0504 205.799 53.0315 205.797 53.0117 205.795C39.2845 204.44 26.9546 198.373 17.6709 189.281C17.6096 189.221 17.5559 189.169 17.5195 189.133L17.4424 189.058L17.4336 189.048L17.4111 189.025C17.4055 189.02 17.3975 189.013 17.3896 189.005L17.2354 188.852L17.1133 188.73L16.3311 187.927C16.3267 187.922 16.3213 187.917 16.3164 187.912C16.2951 187.89 16.2642 187.857 16.2275 187.818L15.8408 187.408C15.8373 187.405 15.8328 187.4 15.8291 187.396C15.8054 187.371 15.7715 187.335 15.7324 187.293L15.3379 186.865V186.864L15.2686 186.789V186.788C14.8224 186.297 14.387 185.8 13.9629 185.3L13.8213 185.133L13.8154 185.125C13.7495 185.047 13.67 184.953 13.585 184.851L13.3154 184.523C13.3129 184.52 13.3102 184.517 13.3076 184.514C13.2546 184.449 13.2042 184.387 13.1592 184.332V184.331L12.3984 183.375C4.63682 173.409 0.000271139 160.85 0 147.251V147.103C0.00464141 144.442 0.190754 141.771 0.561523 139.11C0.572202 139.033 0.58146 138.966 0.586914 138.929C0.594568 138.876 0.593821 138.878 0.595703 138.865L0.597656 138.853C0.602198 138.821 0.630548 138.619 0.657227 138.442C2.11823 128.738 5.94765 119.813 11.5166 112.286V112.285C11.5185 112.283 11.521 112.279 11.5244 112.274C11.5277 112.27 11.5331 112.263 11.5381 112.256C11.557 112.23 11.5981 112.175 11.6455 112.111L11.6689 112.078C11.7175 112.013 11.7589 111.96 11.7861 111.924C11.7876 111.922 11.7895 111.92 11.791 111.918C17.1161 104.814 23.8339 99.1947 31.3232 95.2383C36.524 92.4836 42.1922 90.4842 48.1719 89.3867L48.7529 89.2822C48.8256 89.2696 48.8868 89.2593 48.9189 89.2539C48.9284 89.2523 48.9377 89.2511 48.9443 89.25C48.9517 89.2488 48.9576 89.2478 48.9619 89.2471L49.0332 89.2354L49.4531 89.1523C53.7392 88.1691 56.4043 83.3055 54.9941 79.0869C49.7142 63.2942 50.2167 44.5298 58.9385 29.4258L59.3213 28.7734ZM130.184 22.8789C110.496 11.7589 85.4808 18.5561 74.1504 38.1777C66.8151 50.8812 67.004 65.864 73.334 77.9668C76.4886 83.9983 77.6606 91.3213 74.2568 97.2158C70.8529 103.11 63.9254 105.757 57.124 106.041C55.4204 106.112 53.7254 106.288 52.0498 106.567C51.9939 106.577 51.9377 106.587 51.8818 106.597C51.8243 106.607 51.7665 106.616 51.709 106.626C47.369 107.378 43.2603 108.807 39.498 110.801C34.2217 113.587 29.4986 117.543 25.7588 122.555C25.7423 122.577 25.7254 122.599 25.709 122.621C25.6788 122.662 25.6482 122.702 25.6182 122.743C21.6987 128.033 19.0149 134.294 17.9922 141.098C17.9777 141.193 17.964 141.29 17.9502 141.386C17.9421 141.443 17.9337 141.5 17.9258 141.557C17.6653 143.423 17.5345 145.297 17.5312 147.164V147.281C17.5314 157.141 20.9911 166.193 26.7617 173.291C26.796 173.333 26.8307 173.376 26.8652 173.418C26.928 173.495 26.9914 173.571 27.0547 173.647C27.1097 173.714 27.1653 173.78 27.2207 173.846C27.255 173.886 27.2898 173.928 27.3242 173.969C27.6222 174.32 27.9265 174.667 28.2373 175.01C28.2533 175.027 28.2701 175.045 28.2861 175.062C28.3779 175.163 28.4706 175.264 28.5635 175.364C28.5869 175.389 28.6113 175.414 28.6348 175.439C28.7263 175.537 28.8185 175.636 28.9111 175.733C28.9284 175.751 28.9456 175.77 28.9629 175.788C29.1492 175.983 29.3377 176.177 29.5283 176.368L29.6191 176.459C29.6653 176.505 29.7124 176.551 29.7588 176.597C29.8118 176.649 29.8646 176.703 29.918 176.755C36.4444 183.149 45.0865 187.394 54.6963 188.343C54.7093 188.344 54.7223 188.345 54.7354 188.347C55.0558 188.378 55.3777 188.406 55.7002 188.43C55.7229 188.431 55.7459 188.433 55.7686 188.435C55.8995 188.444 56.0309 188.453 56.1621 188.461C57.0287 188.516 57.8957 188.544 58.7607 188.544C58.774 188.544 58.7875 188.544 58.8008 188.544C58.8551 188.544 58.9096 188.543 58.9639 188.543C59.0597 188.543 59.1561 188.542 59.252 188.541C66.9707 188.458 74.181 186.257 80.3291 182.491C80.397 182.45 80.4655 182.408 80.5332 182.366C80.5788 182.338 80.6245 182.309 80.6699 182.28C85.3019 179.394 89.4161 175.552 92.6865 170.841C92.7302 170.778 92.7741 170.715 92.8174 170.652C92.8427 170.615 92.8684 170.578 92.8936 170.541C94.8281 167.712 96.419 164.629 97.6074 161.354C99.3661 156.526 100.166 151.512 100.075 146.559C100.266 130.197 106.911 115.388 117.584 104.556C120.604 101.545 123.936 98.8474 127.529 96.5156C128.082 96.157 127.539 96.5078 129.953 95.0293C135.565 91.8714 140.505 87.3735 144.245 81.6768C144.281 81.6235 144.315 81.5691 144.351 81.5156C144.368 81.4895 144.385 81.4627 144.402 81.4365C144.828 80.7868 145.239 80.1213 145.632 79.4404C155.114 63.0199 152.024 42.7918 139.35 29.8965C136.719 27.1798 133.672 24.7773 130.236 22.7891L130.184 22.8789ZM160.977 106.017C157.768 106.017 154.645 106.381 151.646 107.074C133.344 111.299 119.699 127.698 119.699 147.281C119.699 170.07 138.176 188.544 160.969 188.544C162.749 188.544 164.503 188.431 166.224 188.212C166.304 188.202 166.383 188.188 166.463 188.178C167.233 188.075 167.995 187.952 168.751 187.808C187.826 184.172 202.246 167.411 202.246 147.279C202.246 124.491 183.769 106.017 160.977 106.017Z",M1="M130.184 22.8784C110.496 11.7584 85.4808 18.5556 74.1504 38.1772C66.8151 50.8807 67.004 65.8635 73.334 77.9663C76.4886 83.9978 77.6606 91.3208 74.2568 97.2153C70.8529 103.109 63.9255 105.756 57.1241 106.04C55.4205 106.111 53.7255 106.287 52.0499 106.566C51.994 106.576 51.9378 106.586 51.8819 106.596C51.8244 106.606 51.7665 106.615 51.709 106.625C47.369 107.377 43.2604 108.806 39.4981 110.8C34.2218 113.586 29.4987 117.542 25.7589 122.554C25.7424 122.576 25.7254 122.598 25.709 122.62C25.6788 122.661 25.6482 122.701 25.6182 122.742C21.6987 128.032 19.015 134.293 17.9923 141.097C17.9778 141.192 17.964 141.289 17.9502 141.385C17.9421 141.442 17.9337 141.499 17.9258 141.556C17.6653 143.422 17.5345 145.296 17.5312 147.163V147.28C17.5314 157.14 20.9911 166.192 26.7617 173.29C26.796 173.332 26.8307 173.375 26.8652 173.417C26.928 173.494 26.9915 173.57 27.0548 173.646C27.1098 173.713 27.1653 173.779 27.2207 173.845C27.255 173.885 27.2898 173.927 27.3242 173.968C27.6222 174.319 27.9266 174.666 28.2374 175.009C28.2534 175.026 28.2701 175.044 28.2861 175.061C28.3779 175.162 28.4706 175.263 28.5635 175.363C28.5869 175.388 28.6113 175.413 28.6348 175.438C28.7263 175.536 28.8185 175.635 28.9111 175.732C28.9284 175.75 28.9456 175.769 28.9629 175.787C29.1492 175.982 29.3377 176.176 29.5283 176.367L29.6192 176.458C29.6654 176.504 29.7125 176.55 29.7589 176.596C29.8119 176.648 29.8646 176.702 29.918 176.754C36.4444 183.148 45.0865 187.393 54.6964 188.342C54.7094 188.343 54.7224 188.344 54.7355 188.346C55.0559 188.377 55.3777 188.405 55.7002 188.429C55.7229 188.43 55.746 188.432 55.7687 188.434C55.8996 188.443 56.031 188.452 56.1622 188.46C57.0288 188.515 57.8957 188.543 58.7607 188.543C58.774 188.543 58.7875 188.543 58.8008 188.543C58.8551 188.543 58.9097 188.542 58.964 188.542C59.0598 188.542 59.1561 188.541 59.252 188.54C66.9707 188.457 74.1811 186.256 80.3292 182.49C80.3971 182.449 80.4656 182.407 80.5333 182.365C80.5789 182.337 80.6245 182.308 80.6699 182.279C85.3019 179.393 89.4162 175.551 92.6866 170.84C92.7303 170.777 92.7741 170.714 92.8174 170.651C92.8427 170.614 92.8684 170.577 92.8936 170.54C94.8281 167.711 96.4191 164.628 97.6075 161.353C99.3662 156.525 100.166 151.511 100.075 146.558C100.266 130.196 106.911 115.387 117.584 104.555C120.604 101.544 123.936 98.8469 127.529 96.5151C128.082 96.1565 127.539 96.5073 129.953 95.0288C135.565 91.8709 140.505 87.373 144.245 81.6763C144.281 81.623 144.315 81.5686 144.351 81.5151C144.368 81.489 144.385 81.4622 144.402 81.436C144.828 80.7863 145.239 80.1208 145.632 79.4399C155.114 63.0194 152.024 42.7913 139.35 29.896C136.719 27.1793 133.672 24.7768 130.236 22.7886L130.184 22.8784ZM160.977 106.016C157.768 106.016 154.645 106.38 151.646 107.073C133.344 111.298 119.699 127.697 119.699 147.28C119.699 170.069 138.176 188.543 160.969 188.543C162.749 188.543 164.503 188.43 166.224 188.211C166.304 188.201 166.383 188.187 166.463 188.177C167.233 188.074 167.995 187.951 168.751 187.807C187.826 184.171 202.246 167.41 202.246 147.278C202.246 124.49 183.769 106.016 160.977 106.016Z",N1={S:{logoHeightPx:24,barHeightPx:4},M:{logoHeightPx:40,barHeightPx:5},L:{logoHeightPx:56,barHeightPx:6}};function v1(){let t=typeof process<"u"&&process.env&&process.env.NEXT_PUBLIC_WS_URL||"";if(t)return String(t).replace(/\/$/,"");if(typeof window>"u")return d1;let d=window.location?.hostname??"";return String(d==="localhost"||d==="127.0.0.1"?R1:d1).replace(/\/$/,"")}function V1({token:t,streamingUrl:d,streamingUrlBase:g,audioProcessorUrl:L="/audio-processor.js",promptPresetName:Y,vadPresetName:o1,onStateChange:I,logoSrc:R="/ephia_logo_light.svg",theme:S="dark",variant:Q="minimal",size:q="M"}){let E=useContext(K),[G,e1]=useState(0),C=useMemo(()=>d||`${g??v1()}/api/v2/streaming/live`,[d,g]),{chunks:M,isRecording:r,isProcessing:z,isConnected:O,volume:T,error:U,errorCode:Z,permissionState:H,debugMessages:s,startRecording:p,stopRecording:k,clear:N,connect:v,sessionId:h,lastSpeechStartTimestamp:V}=r1({url:C,token:t,currentSessionNum:G,audioProcessorUrl:L});useEffect(()=>{r&&e1(w=>w+1);},[r]);let W=useMemo(()=>M.filter(w=>w.text==="[ERREUR]"),[M]),A=E?.setTranscriptionState??null;useEffect(()=>{let w={chunks:M,isRecording:r,isProcessing:z,isConnected:O,volume:T,lastSpeechStartTimestamp:V??null,sessionId:h,debugMessages:s,error:U,errorCode:Z,permissionState:H,transcriptionErrors:W,startRecording:p,stopRecording:k,clear:N,connect:v};I?.(w),A&&A(w);},[M,r,z,O,V,h,s,U,Z,H,W,I,A]);let m=!t,b=S==="light",D=Q==="standard",J=Math.min(1,Math.max(0,T)),F=Math.sqrt(J),s1=R?.includes("ephia_logo_light")?M1:E1,X=b?"#ffffff":"#262626",{logoHeightPx:B,barHeightPx:x}=N1[q],P=Math.round(B*(220/207)),j=R?.includes("ephia_logo");return jsxs("div",{className:`ephia-transcribe-root ephia-transcribe-root--${S} ephia-transcribe-size--${q}`,children:[jsxs("div",{className:`ephia-transcribe-poweredby ephia-transcribe-poweredby--${S}`,"aria-hidden":true,children:[jsx("button",{type:"button",className:"ephia-transcribe-poweredby-btn",tabIndex:-1,children:"i"}),jsx("div",{className:"ephia-transcribe-poweredby-tooltip",children:"Powered by EPHIA"})]}),r&&jsx("div",{className:"ephia-transcribe-ring",style:{transform:`scale(${1.02+T*.05})`,boxShadow:`0 0 ${15+T*35}px rgba(239, 68, 68, ${.3+T*.7})`}}),jsx("button",{type:"button",onClick:r?k:p,disabled:m,className:"ephia-transcribe-btn",style:{transform:r?`scale(${1.02+T*.1})`:void 0},children:j?jsx("svg",{viewBox:"0 0 220 207",className:`ephia-transcribe-logo-svg ${r?"ephia-transcribe-logo-svg--recording":""}`,style:{height:B,width:P},fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":true,children:jsx("path",{d:s1,fill:X})}):jsx("img",{src:R,alt:"Ephia",className:`ephia-transcribe-logo-img ephia-transcribe-logo-img--${S} ${r?"ephia-transcribe-logo-img--recording":""}`,style:{height:B,width:P}})}),D&&jsx("div",{className:`ephia-transcribe-bar-wrap ephia-transcribe-bar-wrap--${S}`,style:{width:P,height:x},title:"Intensit\xE9 vocale",children:jsx("div",{className:"ephia-transcribe-bar-fill",style:{width:`${r?Math.round(F*100):0}%`}})})]})}
2
+ export{V1 as TranscriptionButton,T1 as TranscriptionProvider,r1 as useStreamingV2,x1 as useTranscription};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ephia/transcribe-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "SDK React pour la transcription vocale Ephia (Provider, useTranscription, TranscriptionButton)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",