This repository was archived by the owner on Apr 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
src/main/java/com/google/cloud/speech/grpc/demos Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,15 +78,15 @@ or [homebrew](http://brew.sh/)) to convert audio files to raw format.
7878You can run the batch client like this:
7979
8080``` sh
81- $ bin/speech-sample-nonstreaming .sh --host=speech.googleapis.com --port=443 \
82- --file =< audio file path > --sampling=< sample rate>
81+ $ bin/speech-sample-sync .sh --host=speech.googleapis.com --port=443 \
82+ --uri =< audio file uri > --sampling=< sample rate>
8383```
8484
8585Try a streaming rate of 16000 and the included sample audio file, as follows:
8686
8787``` sh
88- $ bin/speech-sample-nonstreaming .sh --host=speech.googleapis.com --port=443 \
89- --file =resources/audio.raw --sampling=16000
88+ $ bin/speech-sample-sync .sh --host=speech.googleapis.com --port=443 \
89+ --uri =resources/audio.raw --sampling=16000
9090```
9191
9292### Run the streaming client
Original file line number Diff line number Diff line change 2020import com .google .cloud .speech .v1beta1 .RecognitionAudio ;
2121import com .google .protobuf .ByteString ;
2222
23+ import java .io .File ;
2324import java .io .IOException ;
2425import java .net .URI ;
2526import java .nio .file .Files ;
@@ -43,7 +44,11 @@ public class RecognitionAudioFactory {
4344 */
4445 public static RecognitionAudio createRecognitionAudio (URI uri )
4546 throws IOException {
46- if (uri .getScheme () == null || uri .getScheme ().equals (FILE_SCHEME )) {
47+ if (uri .getScheme () == null ) {
48+ uri = new File (uri .toString ()).toURI ();
49+ Path path = Paths .get (uri );
50+ return audioFromBytes (Files .readAllBytes (path ));
51+ } else if (uri .getScheme ().equals (FILE_SCHEME )) {
4752 Path path = Paths .get (uri );
4853 return audioFromBytes (Files .readAllBytes (path ));
4954 } else if (uri .getScheme ().equals (GS_SCHEME )) {
You can’t perform that action at this time.
0 commit comments