The Wayback Machine - https://web.archive.org/web/20240819235641/https://www.geeksforgeeks.org/how-to-use-cloud-speech-to-text-for-speech-recognition-on-gcp/
Open In App

How To use Cloud Speech-To-Text For Speech Recognition On GCP?

Last Updated : 15 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Google Cloud Platform is one of the famous cloud service providers in the market. With cloud features focusing on deployment and storage, GCP also provides features like speech recognition. This powerful and easy-to-use service is called Cloud speech-to-text. This functionality enables developers to convert spoken language into text with high accuracy. Speech-to-text can be integrated with applications to provide transcriptions, and businesses can use this to enhance their accessibility. In this article, we will be learning about this Cloud Speech-to-Text provided by GCP and how we can use this feature to get transcription of Speech.

Key Terminologies

  • Google Cloud Platform (GCP): Google Cloud Platform is a suite of cloud computing services provided by Google. The service provided by GCP are, computing, storage, machine learning, and more. Check out Google Cloud Platform Tutorial for tutorials on Google Cloud Platform.
  • Cloud Speech-to-Text: Cloud speech-to-text is a service on GCP that enables developers to convert audio input to text using Google’s speech recognition technology. This service can be integrated with other applications via API and helps in providing better accessibility.

Step To Use Cloud Speech-To-Text For Speech Recognition On GCP

Step 1: Open GCP Cloud Console

  • Open the log into Google Cloud Platform. In your web browser go to GCP Cloud and log in with your valid credentials.
  • You must have a valid subscription plan to use the services we are going to use.
  • Make sure that you have an active subscription or a trial plan.

Step 2: Enable Cloud Speech-To-Text API

  • Once you are logged into GCP Console, navigate to “API & Services” section.
  • Click on “Enable APIs and Services“.

Enabling APIs and Services

  • This will open a search bar to search for required APIs. Search for “Cloud Speech-to-Text API“.

API Library

  • Click on it and this will show you details about this API. Click on enable to enable this API for your project.

Cloud Speech To Text API

Step 3: Create A Service Account

  • Next, we need to create a service account to generate Key which will help to authenticate our requests.
  • Service account is a special type of account used by applications and Virtual Machines to authenticate and interact with other GCP services and APIs.
  • Navigate to the “APIs & Services” and click on “Credentials“.

API And Services

  • Click on “Create Credentials” and select “Service Account“.

Creating Credentials

  • Now give a name to this service account and click on “Create and continue“.

Service Account Details

  • For Role, select owner and click on Continue.

Defining roles and conditions

  • Leave all other details as default/ pre-set. Click on Done.

Step 4: Create JSON Key

  • JSON Key, is also known as Service Account Key or Credentials File.
  • It is a JSON (JavaScript Object Notation) file format that contains authentication information for a service account in Google Cloud Platform.
  • To generate the JSON Key for our service account click on the newly created service account.

Create a JSON Key

  • Now go to the Key section and select Create new key.

Creating A New Key

For Key Type select JSON and it will create the Key and a JSON file will be download automatically.

Creating A Private Key

Step 5: Install Required Packages

  • Here we are going to implement this Cloud feature using Python.
  • Open any Python IDE available in your system to procced further. You can also use Google Colab to implement this.
  • We will first upgrade the google-cloud-speech package in Python. If this is not available, the package will be installed.
pip install --upgrade google-cloud-speech


Output

Google Cloud Speech software update

Step 6: Import Library

  • Let’s import the required library for our Cloud Speech-to-Text implementation.
 from google.cloud import speech


  • This module is a part of Google Cloud client library for Python, which provides convenient access to Google Cloud services, including the Cloud Speech-to-Text API.

Step 7: Connect With GCP

  • Now connect the python environment to the Google Cloud service account using the JSON key we have generated. First put the JSON file in the working directory and then execute the following line of code.
client = speech.SpeechClient.from_service_account_file('[file_name].json')


Connecting With GCP

Step 8: Select Speech File

  • Get any audio file that contains some speech and paste it in the current directory.
  • Then specify the path for the audio file and then open it and store it in a variable.

Selecting Speech File

Step 9: Perform Speech-to-Text Operation

  • First we will pass the binary data of audio file contained in the ‘mp3_data’ variable to the Cloud Speech-to-Text API for transcription.
audio_file = speech.RecognitionAudio(content = mp3_data)


  • Now, create a variable to define a configuration object for speech recognition request.
  • We will set the sample rate of the audio file which signifies the number of audio carried per second, in Hertz. Also enable automatic punctuation to get appropriate result including comma, question marks, etc.
  • Lastly define the language-code which is American English (en-US) in this case.
config = speech.RecognitionConfig(
sample_rate_hertz=44100,
enable_automatic_punctuation=True,
language_code='en-US'
)


  • Store the transcription results obtained from the Google Cloud Speech-to-Text API in a response variable.
  • We will call the speech recognition process using specified configuration and audio data.

Output:

Output of Speech Recognition Audio

Step 10: Check Result

  • Let’s try printing the response we got and see what it shows
print(response)


Output:

Printing Of Responses

The response has the following details including,

  • Transcript: This is the text generated by the speech recognition process.
  • Confidence: Confidence indicates the likelihood that the transcribed text accurately represents the spoken words.
  • result_end_time: Incdicates the end time of the audio segment.
  • Language Code: The language code specifies the language of the transcripted text.
  • Total Billed Time: This is the time billed for transcription process mesured in seconds.
  • Request Id: Request id is the unique identifier assigned to the speech recognition request by Google Cloud Speech-to-Text API.

Here, we need only the transcription as output, so let’s format the print statement to get only the transcription.

for result in response.results:
print("Transcript : {} ".format(result.alternatives[0].transcript))


Output:

Transcription of output

Conclusion

Google Cloud Speech-to-Text API offers a powerful and reliable solution for converting audio data into text with high accuracy. By using this Cloud feature, developers can easily integrate speech recognition functionality in their application. We can use this feature for cases like, transcription, voice-controlled interfaces, sentiment analysis and more. Google Cloud Speech-to-Text API provides the tools and functionality to provide accurate and efficient speech recognition as per requirements.

Speech Recognition In GCP – FAQ’s

How To Enable Cloud Speech-to-text Api In GCP?

To enable Cloud Speech-to-Text API in Google Cloud Platform, go to “API & Services” in Cloud Console and search for the Cloud Speech-to-Text API then click on the search result and in the next page, click on enable.

How Accurate Is Cloud Speech-to-text ?

Generally Cloud Speech-to-Text achieves high accuracy rates and Google is continuously improving it. However, the accuracy depends on various factors including, audio quality, background noise, accent, and language complexity.

How Many Languages Are Known To Cloud Speech-to-text ?

Cloud Speech-to-Text supports multiple language and variants including regional accents and dialects. It currently supports over 125 languages. Users can list up to three languages for automatic language recognition.

Is Cloud Speech-to-text Is A Free Service Or Paid ?

Cloud Speech-to-Text is a paid service provided by Google Cloud Platform. Pricing for Cloud Speech-to-Text is based on the duration of the audio and other factors. There are different pricing based on the number of seconds processed per month.

How To Use Cloud Speech-to-text For Free?

There is no option to use Cloud Speech-to-Text for free. However you can get a free trial of Google Cloud Platform which offers $300 credit to use any Google Cloud service, include Cloud Speech-to-Text.



Similar Reads

Building Databases On GCP: Cloud SQL VS Cloud Spanner - Comparing Options
In today's world when everything is available over the internet and more people are getting connected to the internet the amount of information or data is also increasing exponentially. Every application or service on the internet operates on data and is connected to some type of databases. Databases work as a backbone for application as data sourc
7 min read
How to Use Cloud Datastore For NoSQL Database On GCP?
Developers can store and retrieve data using Cloud Datastore, a powerful NoSQL document database offered by Google Cloud Platform (GCP). This detailed article will examine the major elements of using Cloud Datastore as a NoSQL database on GCP, covering everything from setup to advanced querying and performance optimization. What is Cloud Datastore?
6 min read
How to Use Cloud Debugger For Debugging Applications On GCP?
Application debugging is a crucial step in the development process since it enables developers to quickly find and fix problems. Developers can debug their applications running on the Google Cloud Platform (GCP) with the help of a potent tool called Cloud Debugger without interfering with their regular operation. In this article, we'll examine Clou
4 min read
How to Use Cloud Pub/Sub for Event-driven Architecture on GCP?
Pre-requisites: Google Cloud Services Cloud Pub/Sub is a fully managed, scalable messaging system offered by Google Cloud Platform (GCP) that enables asynchronous communication between applications. It is a simple and reliable way to exchange data between services and applications in real time. With its event-driven architecture, Cloud Pub/Sub prov
3 min read
How to Use Cloud SQL For MySQL with Automatic Failover on GCP?
Google Cloud Platform (GCP) is a Cloud Service Provider that offers different service models like Iaas(Infrastructure as a service), Paas(Platform as a service), and Saas(Software as a service). Cloud SQL is a relational Database service offered by Google. Users can run MySQL, SQL Server, and PostgreSQL databases on GCP without having the headache
7 min read
How to Use Cloud NAT For Outbound Internet Access on GCP?
NAT Gateway is a Network address translation gateway that enables multiple devices to access a public network through a single IP address. It is mainly used to conserve registered IP addresses and use private IP addresses instead. Cloud NAT is used to expose internal private resources to the internet. We will see step by step process to do the same
3 min read
How to Use Cloud Identity and Access Management (IAM) For Access Control on GCP?
IAM defines "who can do what on which resource". Cloud IAM (Identity Access Management) offers a standardized set of functions and integrates access management for Google Cloud services into a single solution. You can create and manage permissions for Google Cloud resources using the Identity and Access Management (IAM) service provided by Google C
7 min read
How to Use Cloud TPU for High-Performance Machine Learning on GCP?
Google's Cloud Tensor Processing Units (TPUs) have emerged as a game-changer in the realm of machine learning. Designed to accelerate complex computations, these TPUs offer remarkable performance enhancements, making them an integral part of the Google Cloud Platform (GCP). This article aims to provide a comprehensive guide on how to utilize Cloud
4 min read
What is GCP (Google Cloud Platform) Security?
Pre-requisite: GCP Google when the name arrives it is known for a variety of applications such as Gmail, Drive, and Docs with cloud services. But do we ever think about how the security mechanism is worked for that? How the data is being kept intact with the security keeping in mind for about more than a billion users, you can't bet that security i
8 min read
Cloud Functions in GCP
Cloud Functions are a serverless computing service offered by Google Cloud Platform (GCP). They provide a simple way to run code in response to events with minimal configuration and maintenance. Cloud Functions are event-driven, meaning they can be triggered by events such as changes in data, new messages, and user interactions. Cloud Functions in
5 min read
How To Create Cloud Storage Buckets In GCP ?
It is becoming very important to protect and secure our data since more threats and attacks can be seen nowadays. Cyberattacks and data breaches are very common, and it is very difficult to track them. Some cases of attacks also go unreported and undetected. Before facing such attacks and threats online, we should be informed about these online att
7 min read
How To Configure Cloud Spanner In GCP ?
In today's era when data is everywhere, the demand for databases which can seamlessly accumulate massive amount of data is increasing. Databases also have to provide consistency, reliability and high availability. Google Cloud Platform is one of famous cloud providers in the market providing cloud solutions including storage and databases. Cloud Sp
7 min read
Google Cloud Platform (GCP) Interview Questions 2024
Amongst the most prominent cloud service providers, Google Cloud Platform (GCP) has grown rapidly through offering an extensive selection of solutions and services tailored to various business needs. It can be hard to get ready for a GCP interview if you are a beginner who only recently started out with cloud technology, a seasoned professional hop
15+ min read
What is Datafusion in Google Cloud Platform (GCP) ?
Let's start with an introduction to Cloud Data Fusion. Cloud Data Fusion provides a graphical user interface and APIs that increase time efficiency and reduce complexity. It is user-friendly. Cloud Data Fusion provides you with user user-friendly graphical interface to build data pipelines with NO CODE. It supports parallel query execution, which s
4 min read
Securing Your Cloud: Identity and Access Management (IAM) on GCP
In a rapidly changing digital environment, weather protection is essential. Google Cloud Platform (GCP) manages Identity and Access Management (IAM) information. This article covers the basics and details of the system, as well as detailed instructions on setting up Identity and Access Management (IAM) in GCP. Primary TerminologiesIdentity and Acce
3 min read
Public Cloud vs Private Cloud vs Hybrid Cloud
Pre-requisite: Cloud Computing Cloud computing is a type of remote computer network hosting, where massively distributed computers are connected to the Internet and made available through Internet Protocol networks such as the Internet. Cloud computing involves providing a service over the Internet, on-demand and utility computing, distributed syst
7 min read
Google Cloud vs IBM Cloud: Comparing Cloud Platforms
To be productive in today’s business world, you must have noticed that cloud computing has become the  World Wide Web’s Holy Grail. This implies that choosing the right cloud provider is not a matter of preference but mandatory since you need operational agility as data surges. In this detailed examination, we focus on the two cloud industries; Goo
9 min read
GCP Persistent Disk Types: SSD vs. HDD Comparison and Use Cases
GCP (Google Cloud Platform) offers various options to suit diverse business needs in cloud storage. One fundamental aspect of GCP is Persistent Disks, which provide reliable and scalable storage solutions. However, selecting the appropriate disk type is crucial for optimal performance and cost-effectiveness. SSDs: The Future of StorageExplaining wh
8 min read
Key GCP Management Tools and Monitoring Services
Pre-requisite: Google Cloud Platform Google Cloud Platform (GCP) is a collection of cloud computing services offered by Google, including infrastructure as a service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS) products. These services are designed to provide businesses with the tools and resources they need to run their a
4 min read
Key GCP Compute Services
Pre-requisite:- GCP To create and run a Virtual Machine in the Google Cloud Platform, one needs Compute Services to perform certain operations. Google Cloud Platform's Compute Engine provides a variety of computing options according to users' needs. Some of them are discussed below along with their use cases: Cloud Dataproc:Cloud Dataproc is a mana
4 min read
What is Key GCP Security Services?
Managing security in the cloud needs a different strategy due to constantly evolving threats. Therefore, risk management practices must be an important part of cloud security systems. GCP security tools are a good start for the cloud security journey. The GCP follows a shared responsibility model for the security where customers own the security of
6 min read
How To Create a Free Tier Account on GCP?
Like rivals Amazon Web Services (AWS) and Microsoft Azure, GCP is a provider of public clouds. Customers can use Google's global data center-based computing resources for free or pay-per-use through GCP and other cloud suppliers. GCP offers a comprehensive set of computing services that include everything from data management to web and video deliv
1 min read
How to Create a Load Balancer on GCP?
A load balancer in GCP (Google Cloud Platform) is a service that distributes incoming network traffic across multiple backend resources such as virtual machines (VMs), container instances, and managed instance groups. The main purpose of a load balancer is to improve the availability and scalability of the backend resources by distributing the inco
4 min read
How to Deploy a Web Application on GCP?
Google Cloud Platform is one of the cloud service providers that provide various cloud services for a seamless experience. It provides various services like storage, networks, development tools, Analytics tools, infrastructure, and many more. Benefits Of Deploying Web Applications on Google Cloud Platform GCP provides high availability which makes
4 min read
Creating and Attaching GCP Persistent Disks: Step-by-Step
Creating and attaching Google Cloud Platform (GCP) Persistent Disks is an vital project whilst setting up virtual machines (VMs) and coping with storage within the GCP surroundings. Persistent Disks offer dependable, excessive-performance block storage that can be attached to VM instances. In this step-through-step manual, we will walk via the tech
8 min read
How to Deploy Kubernetes on GCP?
Kubernetes, the open-supply field orchestration platform, has emerged as the standard for coping with containerized applications. Google Cloud Platform (GCP) provides a robust and scalable surrounding for deploying Kubernetes clusters. In this comprehensive manual, we are able to walk you through the steps to set up Kubernetes on GCP, leveraging it
5 min read
How To Create a Pub/Sub Topic on GCP?
Pub/Sub is a messaging service that allows you to send and receive messages between independent applications. Separating the senders and receivers enables secure and consistent communication between independently developed applications. With Pub/Sub, you can expect quick delivery of messages while ensuring their durability. This messaging service i
2 min read
Terraform GCP Resource Automation
Terraform is a popular tool for framework mechanization that permits you to describe your framework in an explanatory way using straightforward language structure or syntax. It gives a way to automate the creation, adjustment, modification, and erasure of cloud assets across various cloud providers, counting GCP (Google Cloud Platform) Pre-requisit
3 min read
How To Create VPC Network In GCP?
A VPC or Virtual Private Cloud allows you to secure your virtual networking environment including IP addresses, subnets, and network gateways. VPC allows users to create a virtually protected environment for their virtual instances on the Cloud platform and have complete access to the environment. VPC provides users the facility to place and manage
10 min read
How To Delete & Create VPC Network In The GCP
Google Cloud Platform (GCP) provides a hearty systems administration foundation that permits clients to make and manage virtual organizations, known as virtual private clouds (VPCs). VPCs empower clients to safely interface with their cloud assets while keeping up with command-over network arrangements. Understanding VPC organization is fundamental
7 min read
three90RightbarBannerImg