Spaces:
Sleeping
Sleeping
Updated Dockerfile for Hugging Face Spaces deployment
Browse files- app/public/app.js +5 -2
- app/server.js +2 -2
app/public/app.js
CHANGED
@@ -84,8 +84,11 @@ async function saveAudioAndTranscription(sentence, index) {
|
|
84 |
|
85 |
// Show translation and play audio
|
86 |
translationElement.textContent = result.translation;
|
87 |
-
audioElement.src = `
|
88 |
-
audioElement.
|
|
|
|
|
|
|
89 |
} else {
|
90 |
console.error('Failed to save the file.');
|
91 |
}
|
|
|
84 |
|
85 |
// Show translation and play audio
|
86 |
translationElement.textContent = result.translation;
|
87 |
+
audioElement.src = `https://${window.location.hostname}:${window.location.port}/download-audio?file_path=${result.audio_path}`;
|
88 |
+
audioElement.load(); // Ensure the audio element loads the new source
|
89 |
+
audioElement.play().catch(error => {
|
90 |
+
console.error('Error playing audio:', error);
|
91 |
+
});
|
92 |
} else {
|
93 |
console.error('Failed to save the file.');
|
94 |
}
|
app/server.js
CHANGED
@@ -78,13 +78,13 @@ app.post('/save-audio', upload.single('audio'), async (req, res) => {
|
|
78 |
sentenceIndex++;
|
79 |
|
80 |
// Copy the audio file to the public directory
|
81 |
-
const publicAudioPath = path.join(publicDir,
|
82 |
fs.copyFile(result.audio_path, publicAudioPath, (err) => {
|
83 |
if (err) {
|
84 |
console.error('Error copying audio file to public directory:', err);
|
85 |
return res.status(500).send('Error copying audio file to public directory');
|
86 |
}
|
87 |
-
res.status(200).json({ audio_path:
|
88 |
});
|
89 |
} else {
|
90 |
console.error('Failed to process the file via FastAPI');
|
|
|
78 |
sentenceIndex++;
|
79 |
|
80 |
// Copy the audio file to the public directory
|
81 |
+
const publicAudioPath = path.join(publicDir, `generated_audio_${sentenceIndex}.wav`);
|
82 |
fs.copyFile(result.audio_path, publicAudioPath, (err) => {
|
83 |
if (err) {
|
84 |
console.error('Error copying audio file to public directory:', err);
|
85 |
return res.status(500).send('Error copying audio file to public directory');
|
86 |
}
|
87 |
+
res.status(200).json({ audio_path: `generated_audio_${sentenceIndex}.wav`, translation: result.translation });
|
88 |
});
|
89 |
} else {
|
90 |
console.error('Failed to process the file via FastAPI');
|