Skip to content

Commit

Permalink
Merge pull request #2382 from sepinf-inc/#2381_FixAudioReport
Browse files Browse the repository at this point in the history
Disable audio transcription if initialization fails when creating reports (#2381)
  • Loading branch information
lfcnassif authored Dec 12, 2024
2 parents cc119ae + e98d8f3 commit ac876db
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class RemoteTranscriptionTask extends AbstractTranscriptTask {

private static AtomicBoolean statsPrinted = new AtomicBoolean();

private static volatile AtomicBoolean init = new AtomicBoolean();

private static long lastUpdateServersTime = 0;

private static class Server {
Expand All @@ -81,7 +83,7 @@ public void init(ConfigurationManager configurationManager) throws Exception {

super.init(configurationManager);

if (!this.isEnabled()) {
if (!isEnabled()) {
return;
}

Expand Down Expand Up @@ -115,8 +117,21 @@ public void init(ConfigurationManager configurationManager) throws Exception {
return;
}

requestServers(true);

synchronized (init) {
if (!init.get()) {
try {
requestServers(true);
} catch (Exception e) {
if (hasIpedDatasource()) {
transcriptConfig.setEnabled(false);
logger.warn("Could not initialize remote transcription. Task disabled.");
} else {
throw e;
}
}
init.set(true);
}
}
}

private static synchronized void requestServers(RemoteTranscriptionTask task, boolean now) throws IOException {
Expand Down Expand Up @@ -163,7 +178,7 @@ private void requestServers(boolean now) throws IOException {
@Override
public void finish() throws Exception {
super.finish();
if (!statsPrinted.getAndSet(true)) {
if (isEnabled() && !statsPrinted.getAndSet(true)) {
int numWorkers = this.worker.manager.getNumWorkers();
DecimalFormat df = new DecimalFormat();
logger.info("Time spent to send audios: {}s", df.format(audioSendingTime.get() / (1000 * numWorkers)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.InputStreamReader;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.Level;
Expand Down Expand Up @@ -42,6 +43,8 @@ public class Wav2Vec2TranscriptTask extends AbstractTranscriptTask {

protected static volatile Level logLevel = Level.forName("MSG", 250);

private static volatile AtomicBoolean init = new AtomicBoolean();

static class Server {
Process process;
BufferedReader reader;
Expand All @@ -68,7 +71,7 @@ public void init(ConfigurationManager configurationManager) throws Exception {

super.init(configurationManager);

if (!this.isEnabled()) {
if (!isEnabled()) {
return;
}

Expand All @@ -85,11 +88,26 @@ public void init(ConfigurationManager configurationManager) throws Exception {

if (!deque.isEmpty())
return;

Server server;
int device = 0;
while ((server = startServer(device++)) != null) {
deque.add(server);

synchronized (init) {
if (!init.get()) {
try {
Server server;
int device = 0;
while ((server = startServer(device++)) != null) {
deque.add(server);
}

} catch (Exception e) {
if (hasIpedDatasource()) {
transcriptConfig.setEnabled(false);
logger.warn("Could not initialize audio transcription. Task disabled.");
} else {
throw e;
}
}
init.set(true);
}
}

logLevel = Level.DEBUG;
Expand Down

0 comments on commit ac876db

Please sign in to comment.