save completed audios
This commit is contained in:
parent
326e521a3e
commit
7fadec40a9
1 changed files with 9 additions and 1 deletions
10
whisper.py
10
whisper.py
|
@ -10,6 +10,10 @@ def audio_callback_closure(client: AsyncClient):
|
|||
f"Audio received in room {room.display_name}\n"
|
||||
f"{room.user_name(event.sender)} | {event.body} | {event.url}"
|
||||
)
|
||||
with open("completed.txt",'r') as file:
|
||||
completed_urls = file.readlines()
|
||||
if event.url in completed_urls:
|
||||
return
|
||||
print("Download audio")
|
||||
audio = await client.download(event.url)
|
||||
files = {'audio_file': audio.body}
|
||||
|
@ -19,12 +23,16 @@ def audio_callback_closure(client: AsyncClient):
|
|||
response = requests.post('http://127.0.0.1:9000/asr?encode=true&language=de&task=transcribe&word_timestamps=false&output=txt', files=files)
|
||||
print("Finished transcribing")
|
||||
room_id = room.room_id
|
||||
body = f"{room.user_name(event.sender)}: {event.body} \n{response.content.decode()}"
|
||||
body = f"{event.body} \n{response.content.decode()}"
|
||||
await client.room_send(
|
||||
room_id=room_id,
|
||||
message_type="m.room.message",
|
||||
content={"msgtype": "m.text", "body": body},
|
||||
)
|
||||
completed_urls.append(event.url)
|
||||
with open("completed.txt",'w') as file:
|
||||
file.writelines(completed_urls)
|
||||
|
||||
return audio_callback
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue