Showing posts with label google-cloud. Show all posts
Showing posts with label google-cloud. Show all posts

Friday, 27 July 2018

Google speech API with Punctuation and word timestamp in PHP

Google speech api with Punctuation and word timestamp

Question: What is Speech Recognition?
Google Cloud Speech-to-Text enables developers to convert audio to text by applying powerful neural network models in an easy to use API. The API recognizes 120 languages and variants.


Question: Does it provide Speech Recognition for real-time streaming?
Yes, Its provide for both real-time streaming or pre-recorded audio.


Question: What are the different languages for it provides speech to text?
https://cloud.google.com/speech-to-text/docs/languages


Question: Does it return immediately?
Cloud Speech-to-Text can stream text results, immediately returning text as it’s recognized from streaming audio or as the user is speaking.
For short audio (less than a min), It return results.

For Longer audio, Its take time (1min -20) depend on audio file length.


Question: What are different Models for Speech to Text?
  1. command_and_search: Best for short queries such as voice commands or voice search.
  2. phone_call: Best for audio that originated from a phone call .
  3. video: Best for audio that originated from video or includes multiple speakers
  4. default: Best for audio that is not one of the specific audio models.

You can set model in following way
$operation = $speech->beginRecognizeOperation(
   'gs://product_id/file_name.wav',
    array('model'=>'video')
); 



Question: What are the pricing for speech to text?
https://cloud.google.com/speech-to-text/pricing



Question: How to set private key in the environment?
putenv('GOOGLE_APPLICATION_CREDENTIALS=priviate_key_json.json'); 



Question: How to get punctuation in results?
punctuation are the character which we use in written. for example comma(,), perios(.), question mark?.
You can get the punctuation in transcription results by providing enableWordTimeOffsets=true in the config.

for example:
You can set enableWordTimeOffsets in following way
$operation = $speech->beginRecognizeOperation(
   'gs://product_id/file_name.wav',
    array('enableWordTimeOffsets'=>true,'model'=>'video')
); 



Question: What is office link for speech to text?
https://cloud.google.com/speech-to-text/


Question: What is Github link for speech to text?
https://github.com/GoogleCloudPlatform/google-cloud-php-speech


Question: How to install the SDK for speech to text?
php composer.phar require google/cloud-speech



Question: How to get the transcription for small audio file.?
$audioFilePath='gs://ar10w12018/1135-19114_720p.wav';//You can place your path here
$speech = new SpeechClient([
    'languageCode' => 'en-US'
]);

// Recognize the speech in an audio file.
$results = $speech->recognize(
   $audioFilePath,
);

foreach ($results as $result) {
    echo $result->topAlternative()['transcript'] . "\n";
}   



Question: How to get the transcription for heavy audio file.?
for heavy files, make sure you have already uploaded to google cloud and you have path.

$audioFilePath='gs://ar10w12018/1135-19114_720p.wav';//You can place your path here
                $speech = new V1p1beta1\SpeechClient([
                    'languageCode' => 'en-US',
                ]);
                $config = new V1p1beta1\RecognitionConfig();
                $config->setLanguageCode('en-US');
                $config->setEnableWordTimeOffsets(true);
                $config->setEnableAutomaticPunctuation(true);
                $config->setModel('video');
                
                $audio = new V1p1beta1\RecognitionAudio();
                $audio->setUri($audioFilePath);
                $operation = $speech->longRunningRecognize($config, $audio);
                
              $result['operation']=$operation->getName();//operation name
 

You can get the results by using Operation Name.
$operationName='194790781308823479';
$speech = new SpeechClient([
    'languageCode' => 'en-US'
]);
$operation = $speech->operation($operationName);

$isComplete = $operation->isComplete();
if($isComplete){
$results=$operation->results();
}



Wednesday, 11 July 2018

Google speech recognition Integration with PHP

Google speech recognition Integration with PHP

Question: What is Speech Recognition?
Google Cloud Speech-to-Text enables developers to convert audio to text by applying powerful neural network models in an easy to use API. The API recognizes 120 languages and variants.


Question: Does it provide Speech Recognition for real-time streaming?
Yes, Its provide for both real-time streaming or pre-recorded audio.


Question: What are the different languages for it provides speech to text?
https://cloud.google.com/speech-to-text/docs/languages


Question: Does it return immediately?
Cloud Speech-to-Text can stream text results, immediately returning text as it’s recognized from streaming audio or as the user is speaking.
For short audio (less than a min), It return results.

For Longer audio, Its take time (1min -20) depend on audio file length.


Question: What are different Models for Speech to Text?
  1. command_and_search: Best for short queries such as voice commands or voice search.
  2. phone_call: Best for audio that originated from a phone call .
  3. video: Best for audio that originated from video or includes multiple speakers
  4. default: Best for audio that is not one of the specific audio models.

You can set model in following way
$operation = $speech->beginRecognizeOperation(
   'gs://product_id/file_name.wav',
    array('model'=>'video')
); 



Question: What are the pricing for speech to text?
https://cloud.google.com/speech-to-text/pricing



Question: How to set private key in the environment?
putenv('GOOGLE_APPLICATION_CREDENTIALS=priviate_key_json.json'); 



Question: How to get punctuation in results?
punctuation are the character which we use in written. for example comma(,), perios(.), question mark?.
You can get the punctuation in transcription results by providing enableWordTimeOffsets=true in the config.

for example:
You can set enableWordTimeOffsets in following way
$operation = $speech->beginRecognizeOperation(
   'gs://product_id/file_name.wav',
    array('enableWordTimeOffsets'=>true,'model'=>'video')
); 



Question: What is office link for speech to text?
https://cloud.google.com/speech-to-text/


Question: What is Github link for speech to text?
https://github.com/GoogleCloudPlatform/google-cloud-php-speech


Question: How to install the SDK for speech to text?
php composer.phar require google/cloud-speech



Question: How to get the transcription for small audio file.?
$audioFilePath='gs://ar10w12018/1135-19114_720p.wav';//You can place your path here
$speech = new SpeechClient([
    'languageCode' => 'en-US'
]);

// Recognize the speech in an audio file.
$results = $speech->recognize(
   $audioFilePath,
);

foreach ($results as $result) {
    echo $result->topAlternative()['transcript'] . "\n";
}   



Question: How to get the transcription for heavy audio file.?
for heavy files, make sure you have already uploaded to google cloud and you have path.

$audioFilePath='gs://ar10w12018/1135-19114_720p.wav';//You can place your path here
$speech = new SpeechClient([
    'languageCode' => 'en-US'
]);

// Recognize the speech in an audio file.
$operation = $speech->beginRecognizeOperation(
   $audioFilePath,
    array('enableWordTimeOffsets'=>true,'model'=>'video')
); 
echo $operation->name(); //operation name

You can get the results by using Operation Name.
$operationName='194790781308823479';
$speech = new SpeechClient([
    'languageCode' => 'en-US'
]);
$operation = $speech->operation($operationName);

$isComplete = $operation->isComplete();
if($isComplete){
$results=$operation->results();
}



Monday, 9 July 2018

How to upload files to Google Cloud with PHP?

How to upload files to Google Cloud with PHP?

Question: What are different ways to access Google Services?
  1. Using Client Libraries like PHP, Node, Java etc
  2. Using Gcloud tool command line tool, in this you need to download the cloud SDK which is available for windows, mac and linux.
  3. Using existing command line, similar to above 2nd point.



Question: Question: How to start with client libraries?
  1. Set up a "GCP Console project" (Skip, if already done).
    https://cloud.google.com/resource-manager/docs/creating-managing-projects
    Create or select a project.
    Enable the Google Speech-to-Text API for that project.
    Create a service account.
    Download a private key as JSON (Important, we need this).
  2. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the private key JSON file that contains your service account key(which you have downloaded)
  3. Install the client library



Question: What is price cost for storage?
https://cloud.google.com/storage/pricing-summary/


Question: What are the use cases for storage?
  1. Media storage for website
  2. Streaming videos and music
  3. Mobile app development
  4. Video transcoding
  5. General data analytics and compute
  6. Storage data for Machine learning
  7. Backup data



Question: What are the use cases for storage?
  1. Multi-Regional: For highest availability of frequently accessed data
  2. Regional: For data accessed frequently within a region (cheaper)
  3. Nearline: data which access once a month (more cheaper)
  4. Coldline: data which accessed once a year (cheapest)



Question: What is price cost for storage?
https://cloud.google.com/storage/pricing-summary/


Question: Who are the Partners of Google storage?
https://cloud.google.com/storage/partners/


Question: How to setup of Google storage for PHP?
Step 1 Go to folder where you want to install

Step 2 Install composer (Skip if already)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"


Step 3: Install the library
php composer.phar require google/cloud-storage



Question: How to create folder in Google cloud?
require_once 'vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;

#Setup the Private Key JSON File in Environment
$credentialFilePath='private_key_JSON_file.json;
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$credentialFilePath);

# Your Google Cloud Platform project ID
$projectId = 'projectName';

# Instantiates a client
$storage = new StorageClient([
    'projectId' => $projectId
]);

# The name for the new bucket
$bucketName = 'mynew-test-bucket';

# Creates the new bucket
$bucket = $storage->createBucket($bucketName);

Question: How to upload file in Google cloud folder?

require_once 'vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;

#Setup the Private Key JSON File in Environment
$credentialFilePath='private_key_JSON_file.json;
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$credentialFilePath);

# Your Google Cloud Platform project ID
$projectId = 'projectName';

$storage = new StorageClient();
$bucket = $storage->bucket($projectId);

# Upload a file to the bucket.
$bucket->upload(
    fopen('/downloaded/file.mp3','r')
); 



Question: How to delete file from Google cloud folder?

require_once 'vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;

#Setup the Private Key JSON File in Environment
$credentialFilePath='private_key_JSON_file.json;
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$credentialFilePath);

# Your Google Cloud Platform project ID
$projectId = 'projectName';

$storage = new StorageClient();
$bucket = $storage->bucket($projectId);

$object = $bucket->object($sourceFile); 
$object->delete(); 



Question: What is office link for gcloud storage?
https://cloud.google.com/storage/


Question: What is Github link for gcloud storage (with PHP)?
https://github.com/GoogleCloudPlatform/google-cloud-php