Skip to content

Commit

Permalink
Load env vars from any .env file
Browse files Browse the repository at this point in the history
Custom listener timeout and phrase limit
Update README.md and docs
  • Loading branch information
dormant-user committed Sep 10, 2023
1 parent 846b21e commit 52c6ee4
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ __pycache__
_build
venv
logs
.env
*.env
speech_synthesis.wav
temp*.py
dist
Expand Down
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,30 @@ if __name__ == '__main__':
```

### Environment Variables
Env vars are loaded from a `.env` file and validated using `pydantic`
<details>
<summary><strong><i>To use custom .env files</i></strong></summary>

If the filename is anything other than `.env`, set the filename as an env var `env_file` before importing `jarvis_ui`

```python
import os
os.environ['env_file'] = "jarvis_ui.env"

import jarvis_ui

if __name__ == '__main__':
jarvis_ui.start()
```

</details>

#### Mandatory
- **REQUEST_URL**: URL to which the API call has to be made. Can be `localhost` or a `tunneled` URL behind a reverse proxy/CDN.
- **TOKEN**: Authentication token.

#### Optional
- **HEART_BEAT**: Defaults to `None` - _If # of seconds is set, background health check with the server will be enabled_
- **HEART_BEAT**: Defaults to `None` - _Interval in seconds to trigger background healthcheck on the server with automatic restart_
- **DEBUG**: Defaults to `False` - _Enable debug level logging_
<br><br>
- **SPEECH_TIMEOUT**: Defaults to `0` for macOS, `10` for Windows - _Timeout for speech synthesis_
Expand All @@ -44,22 +62,31 @@ if __name__ == '__main__':
- **VOICE_RATE**: Defaults to the value in `py3-tts` module - _Speed/rate at which the text should be spoken_
- **VOICE_PITCH**: Defaults to the value in `py3-tts` module - _Currently available only for Linux OS_
<br><br>
- **VOICE_TIMEOUT**: Defaults to `3` - _Timeout for listener once wake word is detected - Awaits for a speech to begin until this limit_
- **VOICE_PHRASE_LIMIT**: Defaults to `None` - _Timeout for phrase once listener is activated - Listener will be deactivated after this limit_
- **LISTENER_TIMEOUT**: Defaults to `2` - _Timeout for listener once wake word is detected - Awaits for a speech to begin until this limit_
- **LISTENER_PHRASE_LIMIT**: Defaults to `5` - _Timeout for phrase once listener is activated - Listener will be deactivated after this limit_
- **RECOGNIZER_SETTINGS**: JSON object of customized speech recognition settings.

**Custom settings for speech recognition**
- **RECOGNIZER_SETTINGS**: `'{"energy_threshold": 1100, "dynamic_energy_threshold": false, "pause_threshold": 1, "phrase_threshold": 0.1}'`
<details>
<summary><strong>Custom settings for speech recognition</strong></summary>

The default values for **RECOGNIZER_SETTINGS** are customized according to the author's voice pitch.
Please use [test_listener.py](https://github.com/thevickypedia/Jarvis_UI/blob/main/test_listener.py) to figure out the suitable values in a trial and error method.

Sample settings (formatted as JSON object)<br>

**RECOGNIZER_SETTINGS**: `'{"energy_threshold": 1100, "dynamic_energy_threshold": false, "pause_threshold": 1, "phrase_threshold": 0.1}'`

**Description**
- **energy_threshold**: Minimum audio energy to consider for recording. Greater the value, louder the voice should be.
- **dynamic_energy_threshold**: Change considerable audio **energy_threshold** dynamically.
- **pause_threshold**: Seconds of non-speaking audio before a phrase is considered complete.
- **phrase_threshold**: Minimum seconds of speaking audio before it can be considered a phrase - values below this are ignored. This helps to filter out clicks and pops.
- **non_speaking_duration**: Seconds of non-speaking audio to keep on both sides of the recording.

</details>

---

:bulb: &nbsp; **Refer Jarvis' [README](https://github.com/thevickypedia/Jarvis/blob/master/README.md) for more information on setting up the backend server.**

### Coding Standards
Expand Down
31 changes: 22 additions & 9 deletions docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ <h2>Kick off<a class="headerlink" href="#kick-off" title="Permalink to this head
</section>
<section id="environment-variables">
<h2>Environment Variables<a class="headerlink" href="#environment-variables" title="Permalink to this heading"></a></h2>
<section id="mandatory">
<p>Env vars are loaded from a <code class="docutils literal notranslate"><span class="pre">.env</span></code> file and validated using <code class="docutils literal notranslate"><span class="pre">pydantic</span></code></p>
<details>
<summary><strong><i>To use custom .env files</i></strong></summary><p>If the filename is anything other than <code class="docutils literal notranslate"><span class="pre">.env</span></code>, set the filename as an env var <code class="docutils literal notranslate"><span class="pre">env_file</span></code> before importing <code class="docutils literal notranslate"><span class="pre">jarvis_ui</span></code></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;env_file&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;jarvis_ui.env&quot;</span>

<span class="kn">import</span> <span class="nn">jarvis_ui</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
<span class="n">jarvis_ui</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
</pre></div>
</div>
</details><section id="mandatory">
<h3>Mandatory<a class="headerlink" href="#mandatory" title="Permalink to this heading"></a></h3>
<ul class="simple">
<li><p><strong>REQUEST_URL</strong>: URL to which the API call has to be made. Can be <code class="docutils literal notranslate"><span class="pre">localhost</span></code> or a <code class="docutils literal notranslate"><span class="pre">tunneled</span></code> URL behind a reverse proxy/CDN.</p></li>
Expand All @@ -76,7 +88,7 @@ <h3>Mandatory<a class="headerlink" href="#mandatory" title="Permalink to this he
<section id="optional">
<h3>Optional<a class="headerlink" href="#optional" title="Permalink to this heading"></a></h3>
<ul class="simple">
<li><p><strong>HEART_BEAT</strong>: Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code> - <em>If # of seconds is set, background health check with the server will be enabled</em></p></li>
<li><p><strong>HEART_BEAT</strong>: Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code> - <em>Interval in seconds to trigger background healthcheck on the server with automatic restart</em></p></li>
<li><p><strong>DEBUG</strong>: Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code> - <em>Enable debug level logging</em>
<br><br></p></li>
<li><p><strong>SPEECH_TIMEOUT</strong>: Defaults to <code class="docutils literal notranslate"><span class="pre">0</span></code> for macOS, <code class="docutils literal notranslate"><span class="pre">10</span></code> for Windows - <em>Timeout for speech synthesis</em>
Expand All @@ -90,15 +102,15 @@ <h3>Optional<a class="headerlink" href="#optional" title="Permalink to this head
<li><p><strong>VOICE_RATE</strong>: Defaults to the value in <code class="docutils literal notranslate"><span class="pre">py3-tts</span></code> module - <em>Speed/rate at which the text should be spoken</em></p></li>
<li><p><strong>VOICE_PITCH</strong>: Defaults to the value in <code class="docutils literal notranslate"><span class="pre">py3-tts</span></code> module - <em>Currently available only for Linux OS</em>
<br><br></p></li>
<li><p><strong>VOICE_TIMEOUT</strong>: Defaults to <code class="docutils literal notranslate"><span class="pre">3</span></code> - <em>Timeout for listener once wake word is detected - Awaits for a speech to begin until this limit</em></p></li>
<li><p><strong>VOICE_PHRASE_LIMIT</strong>: Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code> - <em>Timeout for phrase once listener is activated - Listener will be deactivated after this limit</em></p></li>
</ul>
<p><strong>Custom settings for speech recognition</strong></p>
<ul class="simple">
<li><p><strong>RECOGNIZER_SETTINGS</strong>: <code class="docutils literal notranslate"><span class="pre">'{&quot;energy_threshold&quot;:</span> <span class="pre">1100,</span> <span class="pre">&quot;dynamic_energy_threshold&quot;:</span> <span class="pre">false,</span> <span class="pre">&quot;pause_threshold&quot;:</span> <span class="pre">1,</span> <span class="pre">&quot;phrase_threshold&quot;:</span> <span class="pre">0.1}'</span></code></p></li>
<li><p><strong>LISTENER_TIMEOUT</strong>: Defaults to <code class="docutils literal notranslate"><span class="pre">2</span></code> - <em>Timeout for listener once wake word is detected - Awaits for a speech to begin until this limit</em></p></li>
<li><p><strong>LISTENER_PHRASE_LIMIT</strong>: Defaults to <code class="docutils literal notranslate"><span class="pre">5</span></code> - <em>Timeout for phrase once listener is activated - Listener will be deactivated after this limit</em></p></li>
<li><p><strong>RECOGNIZER_SETTINGS</strong>: JSON object of customized speech recognition settings.</p></li>
</ul>
<p>The default values for <strong>RECOGNIZER_SETTINGS</strong> are customized according to the author’s voice pitch.
<details>
<summary><strong>Custom settings for speech recognition</strong></summary><p>The default values for <strong>RECOGNIZER_SETTINGS</strong> are customized according to the author’s voice pitch.
Please use <a class="reference external" href="https://github.com/thevickypedia/Jarvis_UI/blob/main/test_listener.py">test_listener.py</a> to figure out the suitable values in a trial and error method.</p>
<p>Sample settings (formatted as JSON object)<br></p>
<p><strong>RECOGNIZER_SETTINGS</strong>: <code class="docutils literal notranslate"><span class="pre">'{&quot;energy_threshold&quot;:</span> <span class="pre">1100,</span> <span class="pre">&quot;dynamic_energy_threshold&quot;:</span> <span class="pre">false,</span> <span class="pre">&quot;pause_threshold&quot;:</span> <span class="pre">1,</span> <span class="pre">&quot;phrase_threshold&quot;:</span> <span class="pre">0.1}'</span></code></p>
<p><strong>Description</strong></p>
<ul class="simple">
<li><p><strong>energy_threshold</strong>: Minimum audio energy to consider for recording. Greater the value, louder the voice should be.</p></li>
Expand All @@ -107,6 +119,7 @@ <h3>Optional<a class="headerlink" href="#optional" title="Permalink to this head
<li><p><strong>phrase_threshold</strong>: Minimum seconds of speaking audio before it can be considered a phrase - values below this are ignored. This helps to filter out clicks and pops.</p></li>
<li><p><strong>non_speaking_duration</strong>: Seconds of non-speaking audio to keep on both sides of the recording.</p></li>
</ul>
</details><hr class="docutils" />
<p>:bulb:   <strong>Refer Jarvis’ <a class="reference external" href="https://github.com/thevickypedia/Jarvis/blob/master/README.md">README</a> for more information on setting up the backend server.</strong></p>
</section>
</section>
Expand Down
37 changes: 32 additions & 5 deletions docs/_sources/README.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,30 @@ if __name__ == '__main__':
```

### Environment Variables
Env vars are loaded from a `.env` file and validated using `pydantic`
<details>
<summary><strong><i>To use custom .env files</i></strong></summary>

If the filename is anything other than `.env`, set the filename as an env var `env_file` before importing `jarvis_ui`

```python
import os
os.environ['env_file'] = "jarvis_ui.env"

import jarvis_ui

if __name__ == '__main__':
jarvis_ui.start()
```

</details>

#### Mandatory
- **REQUEST_URL**: URL to which the API call has to be made. Can be `localhost` or a `tunneled` URL behind a reverse proxy/CDN.
- **TOKEN**: Authentication token.

#### Optional
- **HEART_BEAT**: Defaults to `None` - _If # of seconds is set, background health check with the server will be enabled_
- **HEART_BEAT**: Defaults to `None` - _Interval in seconds to trigger background healthcheck on the server with automatic restart_
- **DEBUG**: Defaults to `False` - _Enable debug level logging_
<br><br>
- **SPEECH_TIMEOUT**: Defaults to `0` for macOS, `10` for Windows - _Timeout for speech synthesis_
Expand All @@ -44,22 +62,31 @@ if __name__ == '__main__':
- **VOICE_RATE**: Defaults to the value in `py3-tts` module - _Speed/rate at which the text should be spoken_
- **VOICE_PITCH**: Defaults to the value in `py3-tts` module - _Currently available only for Linux OS_
<br><br>
- **VOICE_TIMEOUT**: Defaults to `3` - _Timeout for listener once wake word is detected - Awaits for a speech to begin until this limit_
- **VOICE_PHRASE_LIMIT**: Defaults to `None` - _Timeout for phrase once listener is activated - Listener will be deactivated after this limit_
- **LISTENER_TIMEOUT**: Defaults to `2` - _Timeout for listener once wake word is detected - Awaits for a speech to begin until this limit_
- **LISTENER_PHRASE_LIMIT**: Defaults to `5` - _Timeout for phrase once listener is activated - Listener will be deactivated after this limit_
- **RECOGNIZER_SETTINGS**: JSON object of customized speech recognition settings.

**Custom settings for speech recognition**
- **RECOGNIZER_SETTINGS**: `'{"energy_threshold": 1100, "dynamic_energy_threshold": false, "pause_threshold": 1, "phrase_threshold": 0.1}'`
<details>
<summary><strong>Custom settings for speech recognition</strong></summary>

The default values for **RECOGNIZER_SETTINGS** are customized according to the author's voice pitch.
Please use [test_listener.py](https://github.com/thevickypedia/Jarvis_UI/blob/main/test_listener.py) to figure out the suitable values in a trial and error method.

Sample settings (formatted as JSON object)<br>

**RECOGNIZER_SETTINGS**: `'{"energy_threshold": 1100, "dynamic_energy_threshold": false, "pause_threshold": 1, "phrase_threshold": 0.1}'`

**Description**
- **energy_threshold**: Minimum audio energy to consider for recording. Greater the value, louder the voice should be.
- **dynamic_energy_threshold**: Change considerable audio **energy_threshold** dynamically.
- **pause_threshold**: Seconds of non-speaking audio before a phrase is considered complete.
- **phrase_threshold**: Minimum seconds of speaking audio before it can be considered a phrase - values below this are ignored. This helps to filter out clicks and pops.
- **non_speaking_duration**: Seconds of non-speaking audio to keep on both sides of the recording.

</details>

---

:bulb: &nbsp; **Refer Jarvis' [README](https://github.com/thevickypedia/Jarvis/blob/master/README.md) for more information on setting up the backend server.**

### Coding Standards
Expand Down
12 changes: 6 additions & 6 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,15 @@ <h2 id="L">L</h2>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis_ui.modules.models.Settings.legacy">legacy (jarvis_ui.modules.models.Settings attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis_ui.executables.helper.linux_restart">linux_restart() (in module jarvis_ui.executables.helper)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis_ui.executables.listener.listen">listen() (in module jarvis_ui.executables.listener)</a>
</li>
<li><a href="index.html#jarvis_ui.modules.models.EnvConfig.listener_phrase_limit">listener_phrase_limit (jarvis_ui.modules.models.EnvConfig attribute)</a>
</li>
<li><a href="index.html#jarvis_ui.modules.models.EnvConfig.listener_timeout">listener_timeout (jarvis_ui.modules.models.EnvConfig attribute)</a>
</li>
</ul></td>
</tr></table>
Expand Down Expand Up @@ -444,16 +448,12 @@ <h2 id="V">V</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis_ui.modules.models.EnvConfig.voice_name">voice_name (jarvis_ui.modules.models.EnvConfig attribute)</a>
</li>
<li><a href="index.html#jarvis_ui.modules.models.EnvConfig.voice_phrase_limit">voice_phrase_limit (jarvis_ui.modules.models.EnvConfig attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis_ui.modules.models.EnvConfig.voice_pitch">voice_pitch (jarvis_ui.modules.models.EnvConfig attribute)</a>
</li>
<li><a href="index.html#jarvis_ui.modules.models.EnvConfig.voice_rate">voice_rate (jarvis_ui.modules.models.EnvConfig attribute)</a>
</li>
<li><a href="index.html#jarvis_ui.modules.models.EnvConfig.voice_timeout">voice_timeout (jarvis_ui.modules.models.EnvConfig attribute)</a>
</li>
</ul></td>
</tr></table>
Expand Down
Loading

0 comments on commit 52c6ee4

Please sign in to comment.