From 5e3c5e9131222dd1b825939a5d3b92d0cb3ce944 Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Tue, 7 Apr 2020 13:30:25 +0200 Subject: [PATCH] Fix #2888: Use start-after / end-before for API example line references --- doc/C-Examples.rst | 10 ++++++++-- doc/Java-Examples.rst | 10 ++++++++-- doc/NodeJS-Examples.rst | 10 ++++++++-- doc/Python-Examples.rst | 10 ++++++++-- native_client/client.cc | 4 ++++ .../org/mozilla/deepspeech/DeepSpeechActivity.java | 4 ++++ native_client/javascript/client.ts | 4 ++++ native_client/python/client.py | 4 ++++ 8 files changed, 48 insertions(+), 8 deletions(-) diff --git a/doc/C-Examples.rst b/doc/C-Examples.rst index 2fde5ad3..03a19316 100644 --- a/doc/C-Examples.rst +++ b/doc/C-Examples.rst @@ -1,13 +1,17 @@ C API Usage example =================== +Examples are from `native_client/client.cc`. + Creating a model instance and loading model ------------------------------------------- .. literalinclude:: ../native_client/client.cc :language: c :linenos: - :lines: 370-375,386-390 + :lineno-match: + :start-after: sphinx-doc: c_ref_model_start + :end-before: sphinx-doc: c_ref_model_stop Performing inference -------------------- @@ -15,7 +19,9 @@ Performing inference .. literalinclude:: ../native_client/client.cc :language: c :linenos: - :lines: 59-94 + :lineno-match: + :start-after: sphinx-doc: c_ref_inference_start + :end-before: sphinx-doc: c_ref_inference_stop Full source code ---------------- diff --git a/doc/Java-Examples.rst b/doc/Java-Examples.rst index 51c34e55..46ffa175 100644 --- a/doc/Java-Examples.rst +++ b/doc/Java-Examples.rst @@ -1,13 +1,17 @@ Java API Usage example ====================== +Examples are from `native_client/java/app/src/main/java/org/mozilla/deepspeech/DeepSpeechActivity.java`. + Creating a model instance and loading model ------------------------------------------- .. literalinclude:: ../native_client/java/app/src/main/java/org/mozilla/deepspeech/DeepSpeechActivity.java :language: java :linenos: - :lines: 52 + :lineno-match: + :start-after: sphinx-doc: java_ref_model_start + :end-before: sphinx-doc: java_ref_model_stop Performing inference -------------------- @@ -15,7 +19,9 @@ Performing inference .. literalinclude:: ../native_client/java/app/src/main/java/org/mozilla/deepspeech/DeepSpeechActivity.java :language: java :linenos: - :lines: 101 + :lineno-match: + :start-after: sphinx-doc: java_ref_inference_start + :end-before: sphinx-doc: java_ref_inference_stop Full source code ---------------- diff --git a/doc/NodeJS-Examples.rst b/doc/NodeJS-Examples.rst index 83b37870..9c1197a3 100644 --- a/doc/NodeJS-Examples.rst +++ b/doc/NodeJS-Examples.rst @@ -1,13 +1,17 @@ JavaScript API Usage example ============================= +Examples are from `native_client/javascript/client.ts`. + Creating a model instance and loading model ------------------------------------------- .. literalinclude:: ../native_client/javascript/client.ts :language: javascript :linenos: - :lines: 49,54 + :lineno-match: + :start-after: sphinx-doc: js_ref_model_start + :end-before: sphinx-doc: js_ref_model_stop Performing inference -------------------- @@ -15,7 +19,9 @@ Performing inference .. literalinclude:: ../native_client/javascript/client.ts :language: javascript :linenos: - :lines: 114,118 + :lineno-match: + :start-after: sphinx-doc: js_ref_inference_start + :end-before: sphinx-doc: js_ref_inference_stop Full source code ---------------- diff --git a/doc/Python-Examples.rst b/doc/Python-Examples.rst index 351611ea..9bbc4a3b 100644 --- a/doc/Python-Examples.rst +++ b/doc/Python-Examples.rst @@ -1,13 +1,17 @@ Python API Usage example ======================== +Examples are from `native_client/python/client.cc`. + Creating a model instance and loading model ------------------------------------------- .. literalinclude:: ../native_client/python/client.py :language: python :linenos: - :lines: 111,123 + :lineno-match: + :start-after: sphinx-doc: python_ref_model_start + :end-before: sphinx-doc: python_ref_model_stop Performing inference -------------------- @@ -15,7 +19,9 @@ Performing inference .. literalinclude:: ../native_client/python/client.py :language: python :linenos: - :lines: 143-148 + :lineno-match: + :start-after: sphinx-doc: python_ref_inference_start + :end-before: sphinx-doc: python_ref_inference_stop Full source code ---------------- diff --git a/native_client/client.cc b/native_client/client.cc index 1f7f78eb..72b1dac7 100644 --- a/native_client/client.cc +++ b/native_client/client.cc @@ -162,6 +162,7 @@ LocalDsSTT(ModelState* aCtx, const short* aBuffer, size_t aBufferSize, clock_t ds_start_time = clock(); + // sphinx-doc: c_ref_inference_start if (extended_output) { Metadata *result = DS_SpeechToTextWithMetadata(aCtx, aBuffer, aBufferSize, 1); res.string = CandidateTranscriptToString(&result->transcripts[0]); @@ -198,6 +199,7 @@ LocalDsSTT(ModelState* aCtx, const short* aBuffer, size_t aBufferSize, } else { res.string = DS_SpeechToText(aCtx, aBuffer, aBufferSize); } + // sphinx-doc: c_ref_inference_stop clock_t ds_end_infer = clock(); @@ -393,6 +395,7 @@ main(int argc, char **argv) // Initialise DeepSpeech ModelState* ctx; + // sphinx-doc: c_ref_model_start int status = DS_CreateModel(model, &ctx); if (status != 0) { fprintf(stderr, "Could not create model.\n"); @@ -421,6 +424,7 @@ main(int argc, char **argv) } } } + // sphinx-doc: c_ref_model_stop #ifndef NO_SOX // Initialise SOX diff --git a/native_client/java/app/src/main/java/org/mozilla/deepspeech/DeepSpeechActivity.java b/native_client/java/app/src/main/java/org/mozilla/deepspeech/DeepSpeechActivity.java index f9d9a11e..d82de3a1 100644 --- a/native_client/java/app/src/main/java/org/mozilla/deepspeech/DeepSpeechActivity.java +++ b/native_client/java/app/src/main/java/org/mozilla/deepspeech/DeepSpeechActivity.java @@ -49,8 +49,10 @@ public class DeepSpeechActivity extends AppCompatActivity { private void newModel(String tfliteModel) { this._tfliteStatus.setText("Creating model"); if (this._m == null) { + // sphinx-doc: java_ref_model_start this._m = new DeepSpeechModel(tfliteModel); this._m.setBeamWidth(BEAM_WIDTH); + // sphinx-doc: java_ref_model_stop } } @@ -98,7 +100,9 @@ public class DeepSpeechActivity extends AppCompatActivity { long inferenceStartTime = System.currentTimeMillis(); + // sphinx-doc: java_ref_inference_start String decoded = this._m.stt(shorts, shorts.length); + // sphinx-doc: java_ref_inference_stop inferenceExecTime = System.currentTimeMillis() - inferenceStartTime; diff --git a/native_client/javascript/client.ts b/native_client/javascript/client.ts index e6000fe5..b0f24621 100644 --- a/native_client/javascript/client.ts +++ b/native_client/javascript/client.ts @@ -44,6 +44,7 @@ function candidateTranscriptToString(transcript: Ds.CandidateTranscript): string return retval; } +// sphinx-doc: js_ref_model_start console.error('Loading model from file %s', args['model']); const model_load_start = process.hrtime(); let model = new Ds.Model(args['model']); @@ -53,6 +54,7 @@ console.error('Loaded model in %ds.', totalTime(model_load_end)); if (args['beam_width']) { model.setBeamWidth(args['beam_width']); } +// sphinx-doc: js_ref_model_stop let desired_sample_rate = model.sampleRate(); @@ -110,6 +112,7 @@ audioStream.on('finish', () => { console.error('Running inference.'); const audioLength = (audioBuffer.length / 2) * (1 / desired_sample_rate); + // sphinx-doc: js_ref_inference_start if (args['extended']) { let metadata = model.sttWithMetadata(audioBuffer, 1); console.log(candidateTranscriptToString(metadata.transcripts[0])); @@ -117,6 +120,7 @@ audioStream.on('finish', () => { } else { console.log(model.stt(audioBuffer)); } + // sphinx-doc: js_ref_inference_stop const inference_stop = process.hrtime(inference_start); console.error('Inference took %ds for %ds audio file.', totalTime(inference_stop), audioLength.toPrecision(4)); Ds.FreeModel(model); diff --git a/native_client/python/client.py b/native_client/python/client.py index e45f1cd4..b0aed5c1 100644 --- a/native_client/python/client.py +++ b/native_client/python/client.py @@ -111,7 +111,9 @@ def main(): print('Loading model from file {}'.format(args.model), file=sys.stderr) model_load_start = timer() + # sphinx-doc: python_ref_model_start ds = Model(args.model) + # sphinx-doc: python_ref_model_stop model_load_end = timer() - model_load_start print('Loaded model in {:.3}s.'.format(model_load_end), file=sys.stderr) @@ -143,12 +145,14 @@ def main(): print('Running inference.', file=sys.stderr) inference_start = timer() + # sphinx-doc: python_ref_inference_start if args.extended: print(metadata_to_string(ds.sttWithMetadata(audio, 1).transcripts[0])) elif args.json: print(metadata_json_output(ds.sttWithMetadata(audio, 3))) else: print(ds.stt(audio)) + # sphinx-doc: python_ref_inference_stop inference_end = timer() - inference_start print('Inference took %0.3fs for %0.3fs audio file.' % (inference_end, audio_length), file=sys.stderr)