Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, descrevemos como usar a API Speech-to-Text V2 para gerar legendas automaticamente a partir de arquivos de áudio nos formatos SRT e VTT.
Visão geral
Você pode usar a API Speech-to-Text V2 para gerar legendas automáticas precisas nos formatos SubRip (.srt) e WebVTT (.vtt). Esses formatos são usados para armazenar informações de texto e de marcação de tempo do áudio, possibilitando a exibição de legendas em sincronia com a mídia para legendagem e legendagem descritiva.
A ativação das saídas de legenda em sua solicitação para o Speech-to-Text do Google só é compatível com a API V2. Especificamente, só é possível usar o BatchRecognize para transcrever arquivos de áudio longos. As saídas podem ser salvas em um bucket do Cloud Storage ou retornadas inline.
Vários formatos podem ser especificados ao mesmo tempo para a configuração de saída do Cloud Storage, que é gravada no bucket especificado com diferentes extensões de arquivo.
Ativar saídas de legenda em uma solicitação
Para gerar saídas de legenda SRT ou VTT para seu áudio usando a Conversão de voz em texto do Google, siga as seguintes etapas para ativar as saídas de legenda na solicitação de transcrição:
Faça uma solicitação para o método BatchRecognize da API Speech-to-Text V2 com o campo output_format_config preenchido. Os valores especificados são:
srt, para que a saída siga o formato SubRip(.srt).
native, que é o formato de saída padrão se nenhum formato for especificado como uma solicitação BatchRecognizeResults serializada.
Como a operação é assíncrona, sonde a solicitação até que ela seja concluída.
Vários formatos podem ser especificados ao mesmo tempo para a configuração de saída do Cloud Storage. Eles são gravados no bucket especificado com diferentes extensões de arquivo. Eles são .json para nativo, .srt para SRT e .vtt para compatibilidade com WebVTT, respectivamente.
Se vários formatos forem especificados para a configuração de saída inline, cada um deles estará disponível como um campo na mensagem BatchRecognitionFileResult.inline_result.
O snippet de código abaixo demonstra como ativar saídas de legenda em uma solicitação de transcrição para o Speech-to-Text usando arquivos locais e remotos:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[],[],null,["# Generate WebVTT and SRT captions\n\nThis page describes how to use Speech-to-Text V2 API to automatically generate captions from audio files, in SRT and VTT formats.\n\nOverview\n--------\n\nYou can use the power of Speech-to-Text V2 API to automatically generate accurate captions in both SubRip (.srt) and WebVTT (.vtt) formats. These formats are used to store the text and timing information of audio, making it possible to display subtitles or captions in sync with the media for subtitling and closed captioning.\n\nEnabling caption outputs in your request to Google Speech-to-Text is only supported in the V2 API. Specifically, you can only use `BatchRecognize` to transcribe long audio files. You can save outputs in a Cloud Storage bucket, or they can be returned inline.\nMultiple formats can be specified at the same time for the Cloud Storage output configuration, which is written to the specified bucket with different file extensions.\n\nEnable caption outputs in a request\n-----------------------------------\n\nTo generate SRT or VTT caption outputs for your audio using Google Speech-to-Text, follow the next steps to enable caption outputs in your transcription request:\n\n1. Make a request to the Speech-to-Text V2 API `BatchRecognize` method with the `output_format_config` field populated. Values specified are:\n - `srt`, for the output to follow the [SubRip(.srt) format](https://www.matroska.org/technical/subtitles.html#srt-subtitles).\n - `vtt`, for the output to follow the [WebVTT(.vtt) format](https://www.w3.org/TR/webvtt1/).\n - `native`, which is the default output format if no format is specified as a serialized `BatchRecognizeResults` request.\n2. Since the operation is async, poll the request until it's complete.\n\nMultiple formats can be specified at the same time for the Cloud Storage output configuration. They're written to the specified bucket with different file extensions. Those are `.json` for native, `.srt` for SRT, and `.vtt` for WebVTT support, respectively.\n\nIf multiple formats are specified for the inline output config, each format will be available as a field in the BatchRecognizeFileResult.inline_result message.\n\nThe following code snippet demonstrates how to enable caption outputs in a transcription request to Speech-to-Text using local and remote files: \n\n### API\n\n curl -X POST \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n -H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n https://speech.googleapis.com/v2/projects/my-project/locations/global/recognizers/_:batchRecognize \\\n --data '{\n \"files\": [{\n \"uri\": \"gs://my-bucket/jfk_and_the_press.wav\"\n }],\n \"config\": {\n \"features\": { \"enableWordTimeOffsets\": true },\n \"autoDecodingConfig\": {},\n \"model\": \"long\",\n \"languageCodes\": [\"en-US\"]\n },\n \"recognitionOutputConfig\": {\n \"gcsOutputConfig\": { \"uri\": \"gs://my-bucket\" },\n \"output_format_config\": { \"srt\": {} }\n }\n }'\n\nWhat's next\n-----------\n\n- Learn how to [transcribe long audio files](/speech-to-text/v2/docs/batch-recognize).\n- Learn how to [choose the best transcription model.](./transcription-model)\n- Transcribe audio files using [Chirp](/speech-to-text/v2/docs/chirp-model).\n- For best performance, accuracy, and other tips, see the [best practices](/speech-to-text/v2/docs/best-practices) documentation."]]