3434 * @param string $projectId The Google Cloud project ID.
3535 * @param string $location The location of the recognizer.
3636 * @param string $recognizerId The ID of the recognizer to use.
37- * @param string $audioFile path to an audio file.
37+ * @param string $audioFile path to an audio file (e.x. "test/data/audio32KHz.flac") .
3838 */
3939function transcribe_auto_punctuation (string $ projectId , string $ location , string $ recognizerId , string $ audioFile )
4040{
4141 // create the speech client
42- $ client = new SpeechClient ();
42+ $ apiEndpoint = $ location === 'global ' ? null : sprintf ('%s-speech.googleapis.com ' , $ location );
43+ $ speech = new SpeechClient (['apiEndpoint ' => $ apiEndpoint ]);
4344
4445 // get contents of a file into a string
4546 $ content = file_get_contents ($ audioFile );
@@ -53,6 +54,10 @@ function transcribe_auto_punctuation(string $projectId, string $location, string
5354
5455 $ config = (new RecognitionConfig ())
5556 ->setFeatures ($ features )
57+
58+ // Can also use {@see Google\Cloud\Speech\V2\ExplicitDecodingConfig}
59+ // ->setExplicitDecodingConfig(new ExplicitDecodingConfig([...]);
60+
5661 ->setAutoDecodingConfig (new AutoDetectDecodingConfig ());
5762
5863 $ request = (new RecognizeRequest ())
@@ -61,7 +66,7 @@ function transcribe_auto_punctuation(string $projectId, string $location, string
6166 ->setContent ($ content );
6267
6368 // make the API call
64- $ response = $ client ->recognize ($ request );
69+ $ response = $ speech ->recognize ($ request );
6570 $ results = $ response ->getResults ();
6671
6772 // print results
@@ -74,7 +79,7 @@ function transcribe_auto_punctuation(string $projectId, string $location, string
7479 printf ('Confidence: %s ' . PHP_EOL , $ confidence );
7580 }
7681
77- $ client ->close ();
82+ $ speech ->close ();
7883}
7984# [END speech_transcribe_auto_punctuation]
8085
0 commit comments