Skip to content

Commit

Permalink
chore: fix checkstyle violations
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-zablit committed Oct 14, 2022
1 parent d537a6c commit 7e1a4ee
Showing 1 changed file with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ public boolean isConfiguredProperly() {
public void sendSingleRequest(final TranscriptionRequest request,
final Consumer<TranscriptionResult> resultConsumer) {
// Try to create the client, which can throw an IOException
try {
try
{
// Set the sampling rate and encoding of the audio
AudioFormat format = request.getFormat();
if (!format.getEncoding().equals("LINEAR")) {
if (!format.getEncoding().equals("LINEAR"))
{
throw new IllegalArgumentException("Given AudioFormat" +
"has unexpected" +
"encoding");
Expand All @@ -114,23 +116,29 @@ public void sendSingleRequest(final TranscriptionRequest request,
request.getLocale().toLanguageTag(),
0,
new TranscriptionAlternative(socket.getResult())));
} catch (Exception e) {
}
catch (Exception e)
{
logger.error("Error sending single req", e);
}
}

@Override
public StreamingRecognitionSession initStreamingSession(Participant participant)
throws UnsupportedOperationException {
try {
try
{
WhisperingWebsocketStreamingSession streamingSession = new WhisperingWebsocketStreamingSession(
participant.getDebugName());
streamingSession.transcriptionTag = participant.getTranslationLanguage();
if (streamingSession.transcriptionTag == null) {
if (streamingSession.transcriptionTag == null)
{
streamingSession.transcriptionTag = participant.getSourceLanguage();
}
return streamingSession;
} catch (Exception e) {
}
catch (Exception e)
{
throw new UnsupportedOperationException("Failed to create streaming session", e);
}
}
Expand Down Expand Up @@ -183,10 +191,13 @@ public void onClose(int statusCode, String reason) {
public void onConnect(Session session) {
logger.info("CONNECTED TO WHISPERING WEBSOCKET.");
this.session = session;
try {
try
{
WhisperingContext ctx = new WhisperingContext(0.0);
session.getRemote().sendString(ctx.toJSON().toString());
} catch (Exception e) {
}
catch (Exception e)
{
logger.error("Error while sending context to Whispering server " + debugName, e);
}
}
Expand Down Expand Up @@ -218,15 +229,18 @@ public void sendRequest(TranscriptionRequest request) {
logger.info("SENDING REQUEST");
logger.info(request.getFormat().getSampleRate());
logger.info(request.getDurationInMs());
try {
try
{
//if (sampleRate < 0)
//{
// sampleRate = request.getFormat().getSampleRate();
// session.getRemote().sendString("{\"config\" : {\"sample_rate\" : " + sampleRate + " }}");
//}
ByteBuffer audioBuffer = ByteBuffer.wrap(request.getAudio());
session.getRemote().sendBytes(audioBuffer);
} catch (Exception e) {
}
catch (Exception e)
{
logger.error("Error to send websocket request for participant " + debugName, e);
}
}
Expand All @@ -236,9 +250,12 @@ public void addTranscriptionListener(TranscriptionListener listener) {
}

public void end() {
try {
try
{
session.getRemote().sendString(EOF_MESSAGE);
} catch (Exception e) {
}
catch (Exception e)
{
logger.error("Error to finalize websocket connection for participant " + debugName, e);
}
}
Expand Down Expand Up @@ -275,14 +292,17 @@ public void onClose(int statusCode, String reason) {

@OnWebSocketConnect
public void onConnect(Session session) {
try {
try
{
AudioFormat format = request.getFormat();
WhisperingContext ctx = new WhisperingContext(0.0);
session.getRemote().sendString(ctx.toJSON().toString());
ByteBuffer audioBuffer = ByteBuffer.wrap(request.getAudio());
session.getRemote().sendBytes(audioBuffer);
session.getRemote().sendString(EOF_MESSAGE);
} catch (IOException e) {
}
catch (IOException e)
{
logger.error("Error to transcribe audio", e);
}
}
Expand Down

0 comments on commit 7e1a4ee

Please sign in to comment.