drrobot9 commited on
Commit
90d6b2e
·
verified ·
1 Parent(s): 4e7f8bc

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +8 -7
app/main.py CHANGED
@@ -29,25 +29,26 @@ print("[BOOT] Model loaded")
29
  app = FastAPI(title="LFM2.5 Speech-to-Speech", version="3.0")
30
 
31
 
32
- def wav_header(sr=24000, ch=1, bits=16):
33
- byte_rate = sr * ch * bits // 8
34
- block_align = ch * bits // 8
35
  return (
36
  b"RIFF"
37
- + b"\xff\xff\xff\xff"
38
  + b"WAVEfmt "
39
  + (16).to_bytes(4, "little")
40
  + (1).to_bytes(2, "little")
41
- + ch.to_bytes(2, "little")
42
- + sr.to_bytes(4, "little")
43
  + byte_rate.to_bytes(4, "little")
44
  + block_align.to_bytes(2, "little")
45
  + bits.to_bytes(2, "little")
46
  + b"data"
47
- + b"\xff\xff\xff\xff"
48
  )
49
 
50
 
 
51
  async def generate_response(websocket: WebSocket, audio_np: np.ndarray):
52
 
53
  chat = ChatState(processor)
 
29
  app = FastAPI(title="LFM2.5 Speech-to-Speech", version="3.0")
30
 
31
 
32
+ def wav_header(sample_rate: int, channels: int = 1, bits: int = 16) -> bytes:
33
+ byte_rate = sample_rate * channels * bits // 8
34
+ block_align = channels * bits // 8
35
  return (
36
  b"RIFF"
37
+ + (b"\xff\xff\xff\xff")
38
  + b"WAVEfmt "
39
  + (16).to_bytes(4, "little")
40
  + (1).to_bytes(2, "little")
41
+ + channels.to_bytes(2, "little")
42
+ + sample_rate.to_bytes(4, "little")
43
  + byte_rate.to_bytes(4, "little")
44
  + block_align.to_bytes(2, "little")
45
  + bits.to_bytes(2, "little")
46
  + b"data"
47
+ + (b"\xff\xff\xff\xff")
48
  )
49
 
50
 
51
+
52
  async def generate_response(websocket: WebSocket, audio_np: np.ndarray):
53
 
54
  chat = ChatState(processor)