Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the sleep logic for streaming as per sample rate #279

Merged
merged 11 commits into from
Aug 4, 2016
Merged

Conversation

puneith
Copy link
Contributor

@puneith puneith commented Jul 28, 2016

@jerjou @tswast Please review. Changed the sleep time to absolute 100ms because for 32KKHz the Speech API was complaining about

message: "Audio data is being streamed too slow. Please stream audio data approximately at real time."

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 28, 2016
@codecov-io
Copy link

codecov-io commented Jul 28, 2016

Current coverage is 47.22% (diff: 85.71%)

Merging #279 into master will increase coverage by 2.31%

@@             master       #279   diff @@
==========================================
  Files            78         78          
  Lines          2267       2270     +3   
  Methods           0          0          
  Messages          0          0          
  Branches        154        154          
==========================================
+ Hits           1018       1072    +54   
+ Misses         1216       1167    -49   
+ Partials         33         31     -2   

Powered by Codecov. Last update d7f1d7f...a44e692

// For 16000 Hz sample rate, sleep 100 milliseconds.
Thread.sleep(samplingRate / 160);
// Sleep 100ms
Thread.sleep(100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approximating realtime is dependent on the samplingRate, so you can't hard-code 100ms unless you're also hard-coding the samplingRate.

The calculation here should instead be dependent on samplingRate, buffer size, and encoding. Since encoding is hard-coded to 2 bytes per sample, you should sleep for:

int BYTES_PER_SAMPLE = 2;  // because LINEAR16 - ie 16 bits per sample, at 8 bits per byte
int BYTES_PER_BUFFER = 3200;
int SAMPLES_PER_BUFFER = BYTES_PER_BUFFER / BYTES_PER_SAMPLE; // 1600

int samplesPerMillisecond = samplingRate / 1000;
int millisecondsPerBuffer = SAMPLES_PER_BUFFER / samplesPerMillisecond;
Thread.sleep(millisecondsPerBuffer);

which for 16000 Hz is 1600 / 16 = 100 (as expected), and for 32000 Hz is 1600 / 32 = 50 (which is faster than the original 32000 / 160 = 200). I suspect there was just an error in the original calculation. (feel free to check my math as well - but at least it gives a shorter sleep duration, which is what you'd expect if you increase the sample rate while keeping the buffer size the same)

@puneith
Copy link
Contributor Author

puneith commented Jul 29, 2016

@jerjou PTAL

@jerjou
Copy link
Contributor

jerjou commented Jul 29, 2016

Cool.
Can you add a test with a non-16kHz audio file?

@puneith
Copy link
Contributor Author

puneith commented Aug 4, 2016

@jerjou PTAL

@@ -52,11 +52,13 @@
*/
@RunWith(JUnit4.class)
public class StreamingRecognizeClientTest {
private TestAppender appender;
private Writer writer;
private WriterAppender appender;

@Before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a @BeforeClass, since it's adding an appender (rather than replacing it)? ie if this ones once per test, won't new appenders get added as many times as there are tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to do it for each test so that StringWriter is new. There is an After which I now think should be AfterClass where all added appenders will be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. No - having it in an After makes sense. Sorry - didn't see the After.

@jerjou
Copy link
Contributor

jerjou commented Aug 4, 2016

Travis was unhappy because the api wasn't enabled in the test project. I enabled it and kicked off the build again (I think?).

Thanks for adding the tests! Didn't realize there weren't already tests -_-;

Anyway - looks good from my end - just a couple minor comments. Can you get someone from the java team to sign off on it?

@puneith
Copy link
Contributor Author

puneith commented Aug 4, 2016

@tswast @lesv PTAL

@jerjou
Copy link
Contributor

jerjou commented Aug 4, 2016

Oh - would you mind updating the title to the PR?

@puneith puneith changed the title sleep 100ms instead of sleeping as function of rate Fix the sleep logic for streaming as per sample rate Aug 4, 2016
@lesv
Copy link
Contributor

lesv commented Aug 4, 2016

Minor comment, consider it, change if you wish, then LGTM

@lesv
Copy link
Contributor

lesv commented Aug 4, 2016

LGTM - once travis passes.

@lesv lesv merged commit 16407a9 into master Aug 4, 2016
@lesv lesv deleted the streaming_sleep branch August 11, 2016 16:30
ivanmkc pushed a commit that referenced this pull request Nov 3, 2022
…1.0 (#279)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [com.google.cloud:libraries-bom](https://github.com/GoogleCloudPlatform/cloud-opensource-java) | minor | `12.0.0` -> `12.1.0` |

---

### Renovate configuration

:date: **Schedule**: At any time (no schedule defined).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-datalabeling).
averikitsch pushed a commit that referenced this pull request Nov 9, 2022
…1.0 (#279)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [com.google.cloud:libraries-bom](https://github.com/GoogleCloudPlatform/cloud-opensource-java) | minor | `12.0.0` -> `12.1.0` |

---

### Renovate configuration

:date: **Schedule**: At any time (no schedule defined).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-datalabeling).
minherz pushed a commit that referenced this pull request Nov 9, 2022
🤖 I have created a release \*beep\* \*boop\* 
---
### [0.120.5](https://www.github.com/googleapis/java-errorreporting/compare/v0.120.4...v0.120.5) (2020-10-21)


### Dependencies

* update dependency com.google.cloud:google-cloud-shared-dependencies to v0.13.0 ([#277](https://www.github.com/googleapis/java-errorreporting/issues/277)) ([372fca0](https://www.github.com/googleapis/java-errorreporting/commit/372fca01cbac38951689f533b8d76d2a0bdc74e9))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
minherz pushed a commit that referenced this pull request Nov 10, 2022
🤖 I have created a release \*beep\* \*boop\* 
---
### [0.120.5](https://www.github.com/googleapis/java-errorreporting/compare/v0.120.4...v0.120.5) (2020-10-21)


### Dependencies

* update dependency com.google.cloud:google-cloud-shared-dependencies to v0.13.0 ([#277](https://www.github.com/googleapis/java-errorreporting/issues/277)) ([372fca0](https://www.github.com/googleapis/java-errorreporting/commit/372fca01cbac38951689f533b8d76d2a0bdc74e9))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
minherz pushed a commit that referenced this pull request Nov 10, 2022
🤖 I have created a release \*beep\* \*boop\* 
---
### [0.120.5](https://www.github.com/googleapis/java-errorreporting/compare/v0.120.4...v0.120.5) (2020-10-21)


### Dependencies

* update dependency com.google.cloud:google-cloud-shared-dependencies to v0.13.0 ([#277](https://www.github.com/googleapis/java-errorreporting/issues/277)) ([372fca0](https://www.github.com/googleapis/java-errorreporting/commit/372fca01cbac38951689f533b8d76d2a0bdc74e9))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
Shabirmean pushed a commit that referenced this pull request Nov 11, 2022
…uration to v1.0.21 (#279)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [com.google.cloud.samples:shared-configuration](com/google/cloud/samples/shared-configuration) | patch | `1.0.18` -> `1.0.21` |

---

### Renovate configuration

:date: **Schedule**: At any time (no schedule defined).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-recommender).
Sita04 pushed a commit that referenced this pull request Nov 11, 2022
…-private-ca to v2.1.1 (#279)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-security-private-ca](https://github.com/googleapis/java-) | `2.1.0` -> `2.1.1` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-security-private-ca/2.1.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-security-private-ca/2.1.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-security-private-ca/2.1.1/compatibility-slim/2.1.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-security-private-ca/2.1.1/confidence-slim/2.1.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-security-private-ca).
Shabirmean pushed a commit that referenced this pull request Nov 16, 2022
* samples: add create agent code sample

* Lint fix

* Fix failing test

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Rebased

* Revised Code per comments

* lint fix

* Added Comment for timezone

* Fixed lint

* Used String.format

* Added stdOut Var

* removed parent variable

* Update Tests

* lint fix

* removed parentPath

* removed unreachable statemt

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Revised Code Per Comments

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Shabirmean pushed a commit that referenced this pull request Nov 17, 2022
* samples: add create agent code sample

* Lint fix

* Fix failing test

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Rebased

* Revised Code per comments

* lint fix

* Added Comment for timezone

* Fixed lint

* Used String.format

* Added stdOut Var

* removed parent variable

* Update Tests

* lint fix

* removed parentPath

* removed unreachable statemt

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Revised Code Per Comments

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sita04 pushed a commit that referenced this pull request Jan 17, 2023
…-private-ca to v2.1.1 (#279)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-security-private-ca](https://github.com/googleapis/java-) | `2.1.0` -> `2.1.1` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-security-private-ca/2.1.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-security-private-ca/2.1.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-security-private-ca/2.1.1/compatibility-slim/2.1.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-security-private-ca/2.1.1/confidence-slim/2.1.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-security-private-ca).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants