-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobbie_server.py
53 lines (46 loc) · 1.61 KB
/
jobbie_server.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import socket
import subprocess
def transcribe_audio(audio_data):
# Placeholder: replace with actual transcription logic
print("Transcribing audio...")
# Assume we return the transcription
return "Transcribed text"
def transcode_to_flac(audio_file):
# Placeholder: replace with actual transcoding logic using ffmpeg
print("Transcoding to FLAC...")
flac_filename = audio_file.replace('.wav', '.flac')
subprocess.run(['ffmpeg', '-i', audio_file, '-c:a', 'flac', '-compression_level', '12', flac_filename])
def handle_client(connection):
try:
while True:
# Receive data from the client
data = connection.recv(1024)
if not data:
break
# Process data (assuming it's a path to an audio file)
transcription = transcribe_audio(data.decode())
transcode_to_flac(data.decode())
# Send the transcription back to the client
connection.sendall(transcription.encode())
finally:
connection.close()
def start_server():
host = ''
port = 12345
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((host, port))
serverimeout(0.5)
server_socket.listen()
print("Server listening on port", port)
try:
while True:
try:
client_socket, addr = server_socket.accept()
print('Connected by', addr)
handle_client(client_socket)
except socket.timeout:
continue
finally:
server_socket.close()
if __name__ == "__main__":
start_server()