Esta secção demonstra como transcrever áudio em streaming, como a entrada de um microfone, para texto.
O reconhecimento de voz em streaming permite-lhe transmitir áudio para o serviço de conversão de voz em texto e receber resultados de reconhecimento de voz em streaming em tempo real à medida que o áudio é processado. Consulte também os limites de áudio para pedidos de reconhecimento de voz em streaming. O reconhecimento de voz em streaming só está disponível através do gRPC.
Antes de começar
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
-
Make sure that you have the following role or roles on the project: Cloud Speech Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Aceder ao IAM - Selecione o projeto.
- Clique em Conceder acesso.
-
No campo Novos responsáveis, introduza o identificador do utilizador. Normalmente, este é o endereço de email de uma Conta Google.
- Na lista Selecionar uma função, selecione uma função.
- Para conceder funções adicionais, clique em Adicionar outra função e adicione cada função adicional.
- Clique em Guardar.
Install the Google Cloud CLI.
Se estiver a usar um fornecedor de identidade (IdP) externo, primeiro, tem de iniciar sessão na CLI gcloud com a sua identidade federada.
Para inicializar a CLI gcloud, execute o seguinte comando:
gcloud init
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
-
Make sure that you have the following role or roles on the project: Cloud Speech Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Aceder ao IAM - Selecione o projeto.
- Clique em Conceder acesso.
-
No campo Novos responsáveis, introduza o identificador do utilizador. Normalmente, este é o endereço de email de uma Conta Google.
- Na lista Selecionar uma função, selecione uma função.
- Para conceder funções adicionais, clique em Adicionar outra função e adicione cada função adicional.
- Clique em Guardar.
Install the Google Cloud CLI.
Se estiver a usar um fornecedor de identidade (IdP) externo, primeiro, tem de iniciar sessão na CLI gcloud com a sua identidade federada.
Para inicializar a CLI gcloud, execute o seguinte comando:
gcloud init
-
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
- Consulte a documentação de referência para o reconhecimento de streaming.
- Pratique a transcrição de ficheiros de áudio curtos.
- Saiba como transcrever ficheiros de áudio longos.
- Transcreva ficheiros de áudio com o Chirp.
- Para o melhor desempenho, precisão e outras sugestões, consulte a documentação de práticas recomendadas.
As bibliotecas cliente podem usar as Credenciais padrão da aplicação para fazer a autenticação facilmente com as APIs Google e enviar pedidos para essas APIs. Com as credenciais predefinidas da aplicação, pode testar a sua aplicação localmente e implementá-la sem alterar o código subjacente. Para mais informações, consulte o artigo Autentique-se para usar bibliotecas de cliente.
Certifique-se também de que instalou a biblioteca de cliente.
Realize o reconhecimento de voz em streaming num ficheiro local
Segue-se um exemplo de como realizar o reconhecimento de voz em streaming num ficheiro de áudio local. Existe um limite de 25 KB para o áudio enviado nos pedidos de uma stream. Este limite aplica-se ao pedido StreamingRecognize
inicial e ao tamanho de cada mensagem individual na stream. Exceder este limite vai
gerar um erro.
Python
Embora possa fazer streaming de um ficheiro de áudio local para a API Speech-to-Text, é recomendável que faça o reconhecimento de áudio síncrono.
Limpar
Para evitar incorrer em cobranças na sua Google Cloud conta pelos recursos usados nesta página, siga estes passos.
Consola
gcloud