Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

sample_code_init_fields initial value as a file #945

Closed
jmuk opened this issue Jan 20, 2017 · 9 comments
Closed

sample_code_init_fields initial value as a file #945

jmuk opened this issue Jan 20, 2017 · 9 comments
Assignees
Labels
Core: Sample-gen type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@jmuk
Copy link
Contributor

jmuk commented Jan 20, 2017

Related to #941 and https://github.com/googleapis/googleapis/issues/243, the speech audio data will normally come from a file, and I believe that data coming from a file will be seen in other APIs. It's nicer to extend the sample_code_init_fields syntax to denote that. I'm not sure about its actual specs though.

@jmuk
Copy link
Contributor Author

jmuk commented Jan 20, 2017

Some things like audio.content=file%audio_file.flac ?

@garrettjonesgoogle
Copy link
Member

the syntax template%parameter is already reserved for parameters to path templates. I think the first thing to start with is this: What do you want the generated code to look like?

@jmuk
Copy link
Contributor Author

jmuk commented Jan 21, 2017

Good to know that.

The samplegen should generate the code to read the file from the sample name of the file; with Node.JS, it's gonna be like

var fs = require('fs');
...
var content = fs.readFileSync('audio_file.flac');
var audio = {
  content: content
};
...

@garrettjonesgoogle
Copy link
Member

So then the Java version might be something like this:

  byte[] fileBytes = Files.readAllBytes(Paths.get("audio_file.flac"));
  ByteString content = ByteString.copyFrom(fileBytes);
  RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build();

(There might be a more condensed way to do this.)

So in the config, we need some language-agnostic way to indicate that the content of a file needs to be read with a given name and populated into a given field. Here is one option:

- audio.content=$FILE_BYTES("audio_file.flac")

Here, the $FILE_BYTES indicates a "macro" of sorts for the sample code generator, and tells it to generate code that loads the bytes from a file with the given name. (We have other special dollar-sign features, like $PROJECT_ID and $RANDOM).

@jmuk
Copy link
Contributor Author

jmuk commented Jan 21, 2017

sounds good to me.

@jmuk jmuk added priority: p2 Moderately-important priority. Fix may not be included in next release. Core: Sample-gen labels Jan 21, 2017
@evaogbe evaogbe added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Aug 9, 2017
@evaogbe
Copy link
Contributor

evaogbe commented Aug 14, 2017

@garrettjonesgoogle Is this still relevant?

@garrettjonesgoogle
Copy link
Member

It's still something we could do that would be helpful.

@vchudnov-g
Copy link
Contributor

We are allowing file input in the standalone samples. When we migrate the same samplegen infrastructure to also generate the in-code samples, this will come along for the ride.

@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Jun 27, 2019
@sduskis sduskis removed 🚨 This issue needs some love. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jul 3, 2019
@yihanzhen
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core: Sample-gen type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

7 participants