Spaces:
Sleeping

File size: 779 Bytes
d4255ec
 
2b8eed1
 
 
 
 
 
 
 
 
 
 
 
d4255ec
 
 
 
 
 
 
 
 
 
 
 
 
 
2b8eed1
d4255ec
2b8eed1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const LOCAL_BACKEND_HOST = '127.0.0.1:7860'
const TRANSCRIBE_WS_PATH = '/ws/transcribe'

export type TranscriptSocketMessage =
  | {
      type: 'transcript'
      text: string
      is_final: boolean
      source?: 'hf_asr' | 'mock'
    }
  | {
      type: 'generation_status'
      status: string
    }
  | {
      type: 'error'
      message?: string
      detail?: string
    }

export function getTranscriptionSocketUrl() {
  if (import.meta.env.DEV) {
    return `ws://${LOCAL_BACKEND_HOST}${TRANSCRIBE_WS_PATH}`
  }

  const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
  return `${protocol}//${window.location.host}${TRANSCRIBE_WS_PATH}`
}

export function createTranscriptionSocket(url = getTranscriptionSocketUrl()) {
  return new WebSocket(url)
}