Spaces:
Runtime error
Runtime error
GitLab CI
commited on
Commit
·
a00c4d5
1
Parent(s):
c08f610
Update game build from GitLab CI
Browse files- Dockerfile +7 -6
- server/AudioTranscriber.py +19 -3
- server/__main__.py +1 -2
- server/static/godot/index.pck +0 -0
- server/static/index.html +20 -4
Dockerfile
CHANGED
|
@@ -14,13 +14,14 @@ WORKDIR /app
|
|
| 14 |
RUN apt-get update && apt-get install -y \
|
| 15 |
gcc \
|
| 16 |
portaudio19-dev \
|
| 17 |
-
python3-dev \
|
| 18 |
libasound2-dev \
|
| 19 |
-
libpulse-dev \
|
| 20 |
-
libportaudio2 \
|
| 21 |
-
libportaudiocpp0 \
|
| 22 |
-
libasound2 \
|
| 23 |
-
libasound2-data \
|
|
|
|
| 24 |
wget \
|
| 25 |
gnupg2 \
|
| 26 |
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
| 14 |
RUN apt-get update && apt-get install -y \
|
| 15 |
gcc \
|
| 16 |
portaudio19-dev \
|
| 17 |
+
# python3-dev \
|
| 18 |
libasound2-dev \
|
| 19 |
+
# libpulse-dev \
|
| 20 |
+
# libportaudio2 \
|
| 21 |
+
# libportaudiocpp0 \
|
| 22 |
+
# libasound2 \
|
| 23 |
+
# libasound2-data \
|
| 24 |
+
git \
|
| 25 |
wget \
|
| 26 |
gnupg2 \
|
| 27 |
&& rm -rf /var/lib/apt/lists/*
|
server/AudioTranscriber.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import io
|
|
|
|
| 2 |
import threading
|
| 3 |
from multiprocessing import Queue
|
| 4 |
from queue import Empty
|
|
@@ -19,12 +20,20 @@ logger = logging.getLogger(__name__)
|
|
| 19 |
|
| 20 |
|
| 21 |
class AudioTranscriber(threading.Thread):
|
| 22 |
-
def __init__(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
super().__init__()
|
| 24 |
self.audio_queue = audio_queue
|
| 25 |
self.action_queue = text_queue
|
| 26 |
self.daemon = True # Thread will exit when main program exits
|
|
|
|
|
|
|
| 27 |
|
|
|
|
| 28 |
self.transcriber = WhisperModel(
|
| 29 |
"large",
|
| 30 |
device="cuda",
|
|
@@ -37,8 +46,15 @@ class AudioTranscriber(threading.Thread):
|
|
| 37 |
# Wait for 1 second before timing out and checking again
|
| 38 |
audio_chunk = self.audio_queue.get(timeout=1)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Put the transcription results in the output queue
|
| 44 |
for segment in segments:
|
|
|
|
| 1 |
import io
|
| 2 |
+
from typing import List
|
| 3 |
import threading
|
| 4 |
from multiprocessing import Queue
|
| 5 |
from queue import Empty
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
class AudioTranscriber(threading.Thread):
|
| 23 |
+
def __init__(
|
| 24 |
+
self,
|
| 25 |
+
audio_queue: "Queue[io.BytesIO]",
|
| 26 |
+
text_queue: "Queue[str]",
|
| 27 |
+
language: str = "en",
|
| 28 |
+
):
|
| 29 |
super().__init__()
|
| 30 |
self.audio_queue = audio_queue
|
| 31 |
self.action_queue = text_queue
|
| 32 |
self.daemon = True # Thread will exit when main program exits
|
| 33 |
+
self.max_buffer_size = 3
|
| 34 |
+
self.language = language
|
| 35 |
|
| 36 |
+
self.buffer: List[io.BytesIO] = []
|
| 37 |
self.transcriber = WhisperModel(
|
| 38 |
"large",
|
| 39 |
device="cuda",
|
|
|
|
| 46 |
# Wait for 1 second before timing out and checking again
|
| 47 |
audio_chunk = self.audio_queue.get(timeout=1)
|
| 48 |
|
| 49 |
+
self.buffer.append(audio_chunk)
|
| 50 |
+
|
| 51 |
+
while len(self.buffer) >= self.max_buffer_size:
|
| 52 |
+
_ = self.buffer.pop(0)
|
| 53 |
+
|
| 54 |
+
joined_buffer = b"".join([chunk.getvalue() for chunk in self.buffer])
|
| 55 |
+
segments, info = self.transcriber.transcribe(
|
| 56 |
+
joined_buffer, language=self.language
|
| 57 |
+
)
|
| 58 |
|
| 59 |
# Put the transcription results in the output queue
|
| 60 |
for segment in segments:
|
server/__main__.py
CHANGED
|
@@ -84,7 +84,7 @@ def serve_index():
|
|
| 84 |
|
| 85 |
@app.route("/api/data", methods=["GET"])
|
| 86 |
def get_data():
|
| 87 |
-
return jsonify({"
|
| 88 |
|
| 89 |
|
| 90 |
@app.route("/api/process", methods=["POST"])
|
|
@@ -129,7 +129,6 @@ def process_data():
|
|
| 129 |
|
| 130 |
return jsonify(
|
| 131 |
{
|
| 132 |
-
"message": "Audio chunk received and queued for processing",
|
| 133 |
"status": "success",
|
| 134 |
}
|
| 135 |
)
|
|
|
|
| 84 |
|
| 85 |
@app.route("/api/data", methods=["GET"])
|
| 86 |
def get_data():
|
| 87 |
+
return jsonify({"status": "success"})
|
| 88 |
|
| 89 |
|
| 90 |
@app.route("/api/process", methods=["POST"])
|
|
|
|
| 129 |
|
| 130 |
return jsonify(
|
| 131 |
{
|
|
|
|
| 132 |
"status": "success",
|
| 133 |
}
|
| 134 |
)
|
server/static/godot/index.pck
CHANGED
|
Binary files a/server/static/godot/index.pck and b/server/static/godot/index.pck differ
|
|
|
server/static/index.html
CHANGED
|
@@ -32,12 +32,18 @@
|
|
| 32 |
<script>
|
| 33 |
// URL of the server to send audio chunks
|
| 34 |
const serverUrl = "./api/process"
|
|
|
|
| 35 |
|
| 36 |
// Check server availability first
|
|
|
|
|
|
|
|
|
|
| 37 |
fetch("./api/data", {
|
| 38 |
-
method: 'GET'
|
|
|
|
| 39 |
})
|
| 40 |
.then(response => {
|
|
|
|
| 41 |
if (!response.ok) {
|
| 42 |
throw new Error(`Server check failed: ${response.status}`)
|
| 43 |
}
|
|
@@ -45,8 +51,12 @@
|
|
| 45 |
setupAudioRecording()
|
| 46 |
})
|
| 47 |
.catch(error => {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
console.error('Server check failed:', error)
|
| 49 |
-
|
| 50 |
throw error
|
| 51 |
})
|
| 52 |
|
|
@@ -55,7 +65,7 @@
|
|
| 55 |
// Check if browser supports audio recording
|
| 56 |
if (!navigator.mediaDevices?.getUserMedia) {
|
| 57 |
console.error('Your browser does not support audio recording.')
|
| 58 |
-
|
| 59 |
throw new Error('Audio recording not supported')
|
| 60 |
}
|
| 61 |
|
|
@@ -81,6 +91,9 @@
|
|
| 81 |
const base64Audio = reader.result.split(',')[1]
|
| 82 |
|
| 83 |
// Send as JSON with base64-encoded audio
|
|
|
|
|
|
|
|
|
|
| 84 |
fetch(serverUrl, {
|
| 85 |
method: 'POST',
|
| 86 |
headers: {
|
|
@@ -88,10 +101,13 @@
|
|
| 88 |
},
|
| 89 |
body: JSON.stringify({
|
| 90 |
audio_chunk: base64Audio
|
| 91 |
-
})
|
|
|
|
| 92 |
}).then(response => {
|
|
|
|
| 93 |
console.log('Audio chunk sent successfully')
|
| 94 |
}).catch(error => {
|
|
|
|
| 95 |
console.error('Error sending audio chunk:', error)
|
| 96 |
})
|
| 97 |
}
|
|
|
|
| 32 |
<script>
|
| 33 |
// URL of the server to send audio chunks
|
| 34 |
const serverUrl = "./api/process"
|
| 35 |
+
const FETCH_TIMEOUT = 5000 // 5 seconds timeout
|
| 36 |
|
| 37 |
// Check server availability first
|
| 38 |
+
const controller = new AbortController()
|
| 39 |
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT)
|
| 40 |
+
|
| 41 |
fetch("./api/data", {
|
| 42 |
+
method: 'GET',
|
| 43 |
+
signal: controller.signal
|
| 44 |
})
|
| 45 |
.then(response => {
|
| 46 |
+
clearTimeout(timeout)
|
| 47 |
if (!response.ok) {
|
| 48 |
throw new Error(`Server check failed: ${response.status}`)
|
| 49 |
}
|
|
|
|
| 51 |
setupAudioRecording()
|
| 52 |
})
|
| 53 |
.catch(error => {
|
| 54 |
+
clearTimeout(timeout)
|
| 55 |
+
const errorMessage = error.name === 'AbortError'
|
| 56 |
+
? 'Server request timed out. Please try again later.'
|
| 57 |
+
: 'Could not connect to the server. Please try again later.'
|
| 58 |
console.error('Server check failed:', error)
|
| 59 |
+
console.error(errorMessage)
|
| 60 |
throw error
|
| 61 |
})
|
| 62 |
|
|
|
|
| 65 |
// Check if browser supports audio recording
|
| 66 |
if (!navigator.mediaDevices?.getUserMedia) {
|
| 67 |
console.error('Your browser does not support audio recording.')
|
| 68 |
+
console.error('Please try using a modern browser like Chrome, Firefox, or Edge.')
|
| 69 |
throw new Error('Audio recording not supported')
|
| 70 |
}
|
| 71 |
|
|
|
|
| 91 |
const base64Audio = reader.result.split(',')[1]
|
| 92 |
|
| 93 |
// Send as JSON with base64-encoded audio
|
| 94 |
+
const audioController = new AbortController()
|
| 95 |
+
const audioTimeout = setTimeout(() => audioController.abort(), FETCH_TIMEOUT)
|
| 96 |
+
|
| 97 |
fetch(serverUrl, {
|
| 98 |
method: 'POST',
|
| 99 |
headers: {
|
|
|
|
| 101 |
},
|
| 102 |
body: JSON.stringify({
|
| 103 |
audio_chunk: base64Audio
|
| 104 |
+
}),
|
| 105 |
+
signal: audioController.signal
|
| 106 |
}).then(response => {
|
| 107 |
+
clearTimeout(audioTimeout)
|
| 108 |
console.log('Audio chunk sent successfully')
|
| 109 |
}).catch(error => {
|
| 110 |
+
clearTimeout(audioTimeout)
|
| 111 |
console.error('Error sending audio chunk:', error)
|
| 112 |
})
|
| 113 |
}
|