18
18
package com .google .cloud .speech .grpc .demos ;
19
19
20
20
import com .google .cloud .speech .v1 .AudioRequest ;
21
- import java .net .URI ;
22
- import java .io .IOException ;
23
-
24
21
import com .google .cloud .storage .Blob ;
25
22
import com .google .cloud .storage .BlobId ;
26
23
import com .google .cloud .storage .Storage ;
27
24
import com .google .cloud .storage .StorageOptions ;
28
25
import com .google .protobuf .ByteString ;
29
26
27
+ import java .io .IOException ;
28
+
29
+ import java .net .URI ;
30
30
import java .nio .file .Files ;
31
31
import java .nio .file .Path ;
32
32
import java .nio .file .Paths ;
@@ -41,29 +41,28 @@ public class AudioRequestFactory {
41
41
private static final String GS = "gs" ;
42
42
43
43
/**
44
- * Takes an input URI of form $scheme:// and converts to audio request
44
+ * Takes an input URI of form $scheme:// and converts to audio request.
45
45
*
46
46
* @param uri input uri
47
47
* @return AudioRequest audio request
48
48
*/
49
49
public static AudioRequest createRequest (URI uri )
50
50
throws IOException {
51
- if (uri .getScheme () == null || uri .getScheme ().equals (FILE )) {
51
+ if (uri .getScheme () == null || uri .getScheme ().equals (FILE )) {
52
52
Path path = Paths .get (uri );
53
53
return audioFromBytes (Files .readAllBytes (path ));
54
- }
55
- else if (uri .getScheme ().equals (GS )) {
54
+ } else if (uri .getScheme ().equals (GS )) {
56
55
Storage storage = StorageOptions .defaultInstance ().service ();
57
56
String path = uri .getPath ();
58
57
BlobId blobId = BlobId .of (uri .getHost (), path .substring (1 ,path .length ()));
59
58
Blob blob = storage .get (blobId );
60
59
return audioFromBytes (blob .content ());
61
60
}
62
- throw new RuntimeException ("scheme not supported " + uri .getScheme ());
61
+ throw new RuntimeException ("scheme not supported " + uri .getScheme ());
63
62
}
64
63
65
64
/**
66
- * Convert bytes to AudioRequest
65
+ * Convert bytes to AudioRequest.
67
66
*
68
67
* @param bytes input bytes
69
68
* @return AudioRequest audio request
0 commit comments