File tree 2 files changed +10
-5
lines changed
src/main/java/com/google/cloud/speech/grpc/demos
2 files changed +10
-5
lines changed 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.
78
78
You can run the batch client like this:
79
79
80
80
``` 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>
83
83
```
84
84
85
85
Try a streaming rate of 16000 and the included sample audio file, as follows:
86
86
87
87
``` 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
90
90
```
91
91
92
92
### Run the streaming client
Original file line number Diff line number Diff line change 20
20
import com .google .cloud .speech .v1beta1 .RecognitionAudio ;
21
21
import com .google .protobuf .ByteString ;
22
22
23
+ import java .io .File ;
23
24
import java .io .IOException ;
24
25
import java .net .URI ;
25
26
import java .nio .file .Files ;
@@ -43,7 +44,11 @@ public class RecognitionAudioFactory {
43
44
*/
44
45
public static RecognitionAudio createRecognitionAudio (URI uri )
45
46
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 )) {
47
52
Path path = Paths .get (uri );
48
53
return audioFromBytes (Files .readAllBytes (path ));
49
54
} else if (uri .getScheme ().equals (GS_SCHEME )) {
You can’t perform that action at this time.
0 commit comments