huynhkimthien commited on
Commit
9787f53
·
verified ·
1 Parent(s): df28e1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -18
app.py CHANGED
@@ -86,24 +86,7 @@ async def voice_chat(file: UploadFile = File(...)):
86
  result = whisper_model.transcribe(file_location, language="vi")
87
  user_text = result["text"]
88
  os.remove(file_location)
89
- """@app.post("/voice_chat")
90
- async def voice_chat(request: Request):
91
- # Đọc dữ liệu âm thanh thô từ ESP32 gửi lên
92
- raw_audio = await request.body()
93
- # Giả sử âm thanh là PCM 16-bit mono, sample rate 16000 Hz
94
- sample_rate = 16000
95
- audio_np = np.frombuffer(raw_audio, dtype=np.int16)
96
- # Chuyển thành file WAV trong bộ nhớ
97
- wav_io = io.BytesIO()
98
- wav.write(wav_io, sample_rate, audio_np)
99
- wav_io.seek(0)
100
- # Lưu file WAV tạm để dùng với Whisper
101
- with open("temp_audio.wav", "wb") as f: f.write(wav_io.read())
102
- # Gọi Whisper để chuyển âm thanh thành văn bản
103
- import whisper model = whisper.load_model("base")
104
- result = model.transcribe("temp_audio.wav", language="vi")
105
- user_text = result["text"]
106
- #return JSONResponse(content={"text": user_text})"""
107
  # Kiểm tra yêu cầu mở nhạc
108
  if any(kw in user_text.lower() for kw in ["nghe nhạc", "mở bài hát", "bài hát", "bài"]):
109
  song_name = extract_song_name(user_text)
 
86
  result = whisper_model.transcribe(file_location, language="vi")
87
  user_text = result["text"]
88
  os.remove(file_location)
89
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  # Kiểm tra yêu cầu mở nhạc
91
  if any(kw in user_text.lower() for kw in ["nghe nhạc", "mở bài hát", "bài hát", "bài"]):
92
  song_name = extract_song_name(user_text)