Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. # Includes the autoloader for libraries installed with composer
  2. require __DIR__ . '/vendor/autoload.php';
  3.  
  4. # Imports the Google Cloud client library
  5. use Google\Cloud\Speech\SpeechClient;
  6.  
  7. # Your Google Cloud Platform project ID
  8. $projectId = 'YOUR_PROJECT_ID';
  9.  
  10. # Instantiates a client
  11. $speech = new SpeechClient([
  12. 'projectId' => $projectId,
  13. 'languageCode' => 'en-US',
  14. ]);
  15.  
  16. # The name of the audio file to transcribe
  17. $fileName = __DIR__ . '/resources/audio.raw';
  18.  
  19. # The audio file's encoding and sample rate
  20. $options = [
  21. 'encoding' => 'LINEAR16',
  22. 'sampleRateHertz' => 16000,
  23. ];
  24.  
  25. # Detects speech in the audio file
  26. $results = $speech->recognize(fopen($fileName, 'r'), $options);
  27.  
  28. foreach ($results as $result) {
  29. echo 'Transcription: ' . $result->alternatives()[0]['transcript'] . PHP_EOL;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement