Text to speech error: Synthesis CANCELED: ErrorCode=ServiceTimeout, ErrorDetails=Timeout while synthesizing. USP state: 4. Received audio size: 4320 bytes.

Linfeng Deng 5 Reputation points
2023-07-27T07:50:02.9966667+00:00

After the kubeneters pod run some days, it will throw some exception like:

Synthesis CANCELED: ErrorCode=ServiceTimeout, ErrorDetails=Timeout while synthesizing. USP state: 4. Received audio size: 4320 bytes.

Synthesis CANCELED: ErrorCode=ConnectionFailure, ErrorDetails=Connection was closed by the remote host. Error code: 1011. Error details: Internal server error. USP state: 2. Received audio size: 0 bytes.

Synthesis CANCELED: ErrorCode=ServiceTimeout, ErrorDetails=USP error: timeout waiting for the first audio chunk

Synthesis CANCELED: ErrorCode=ServiceTimeout, ErrorDetails=USP error: timeout waiting for the first audio chunk

Here is my code:

 String tempFilePath = createFullPath(name);
        logger.info("[{}] the audio created temp full path is:{}", projectId, tempFilePath);
        AudioConfig audioConfig = AudioConfig.fromWavFileOutput(tempFilePath);
        SpeechSynthesizer speechSynthesizer = null;
        try {
            speechSynthesizer = new SpeechSynthesizer(speechConfig, audioConfig);
            List<SpeechSynthesisWordBoundaryEventArgs> wordBoundaries = new ArrayList<>();
            List<Long> sceneEndOffsets = new ArrayList<>();
            List<Long> sceneIds = new ArrayList<>();
            Map<Long, List<TranscriptItemVo>> scenes = new ConcurrentHashMap<>();
            final long[] start = {0L};
            speechSynthesizer.SynthesisStarted.addEventListener((o, e) -> {
                start[0] = System.currentTimeMillis();
                logger.info("[{}] SynthesisStarted event at: {}", projectId, start[0]);
            });
            speechSynthesizer.BookmarkReached.addEventListener((o, e) -> {
                sceneEndOffsets.add(e.getAudioOffset());
                sceneIds.add(Long.valueOf(e.getText()));
            });
            speechSynthesizer.SynthesisCompleted.addEventListener((o, e) -> {
                long end = System.currentTimeMillis();
                SpeechSynthesisResult result = e.getResult();
                logger.info("[{}] SynthesisCompleted event at: {}, all the process cost: {} ms", projectId, end, (end - start[0]));
                result.close();
            });
            speechSynthesizer.SynthesisCanceled.addEventListener((o, e) -> {
                SpeechSynthesisResult result = e.getResult();
                SpeechSynthesisCancellationDetails cancellation = SpeechSynthesisCancellationDetails.fromResult(result);
                logger.warn("[{}] Synthesis CANCELED: Reason= {}", projectId, cancellation.getReason());

                if (cancellation.getReason() == CancellationReason.Error) {
                    String errorMsg = String.format(Constants.AZURE_SYNTHETIC_ERROR_MESSAGE, projectId, cancellation.getErrorCode().toString()
                        , cancellation.getErrorDetails());
                    logger.warn(errorMsg);
                    if (cancellation.getErrorDetails().contains("WS_OPEN_ERROR_UNDERLYING_IO_OPEN_FAILED")) {
                        syntheticVoiceResultBo.setSslError(true);
                    }
                    syntheticVoiceResultBo.setErrorMessage(errorMsg);
                }
            });
            speechSynthesizer.WordBoundary.addEventListener((o, e) -> {
                wordBoundaries.add(e);
            });
        } catch (Exception e) {
            logger.error("[{}] failed to create speechSynthesizer:", projectId, e);
        }
        if (Objects.isNull(speechSynthesizer)) {
            return syntheticVoiceResultBo;
        }
        speechSynthesizer.SpeakSsml(str);
        logger.info("[{}] send ssml to azure success, will close the speechSynthesizer", projectId);
        speechSynthesizer.close();
        speechConfig.close();
        return syntheticVoiceResultBo;

Is there anything wrong ?

But this is not always the case. Just these days, the code ran very well before. The error above appeared about 2/30days, I think it is normal. But these days, it appeared more than 100/day, And when the error occured, it will multiple occurrences in a short period of time.

After google, I need to add some information:

  1. I am a paid user. And I did not change the rate limit, because the document said the limit will scall automaticly. I do not know if it's the amount or the deduction issue.
  2. I am using service in Azure, not deployed by myself. The text to speech service, just one service. So I do not know if it's a matter of resources.
  3. I am using com.microsoft.cognitiveservices.speech java sdk version: 1.24.2

Thank you so much.

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,284 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,218 questions
{count} votes