Skip to content

Commit

Permalink
Release v3.9
Browse files Browse the repository at this point in the history
Remove unnecessary thread binding for audio driver
Redo imports during startup
  • Loading branch information
dormant-user committed Oct 3, 2023
1 parent a70c434 commit 2ebd589
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 181 deletions.
14 changes: 2 additions & 12 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,6 @@ <h2 id="D">D</h2>
</li>
</ul></li>
<li><a href="index.html#jarvis.modules.models.classes.RecognizerSettings.dynamic_energy_threshold">dynamic_energy_threshold (jarvis.modules.models.classes.RecognizerSettings attribute)</a>
</li>
<li><a href="index.html#jarvis.modules.models.classes.dynamic_rate">dynamic_rate() (in module jarvis.modules.models.classes)</a>
</li>
</ul></td>
</tr></table>
Expand Down Expand Up @@ -1074,8 +1072,6 @@ <h2 id="I">I</h2>
<li><a href="index.html#jarvis.modules.models.classes.BackgroundTask.ignore_hours">ignore_hours (jarvis.modules.models.classes.BackgroundTask attribute)</a>
</li>
<li><a href="index.html#jarvis.modules.models.classes.TemperatureUnits.IMPERIAL">IMPERIAL (jarvis.modules.models.classes.TemperatureUnits attribute)</a>
</li>
<li><a href="index.html#jarvis.modules.models.classes.import_module">import_module() (in module jarvis.modules.models.classes)</a>
</li>
<li><a href="index.html#jarvis.modules.tv.lg.LGWebOS.increase_volume">increase_volume() (jarvis.modules.tv.lg.LGWebOS method)</a>

Expand Down Expand Up @@ -2175,8 +2171,6 @@ <h2 id="M">M</h2>
<li><a href="index.html#jarvis.modules.exceptions.MissingEnvVars">MissingEnvVars</a>
</li>
<li><a href="index.html#jarvis.modules.facenet.face.FaceNet.MODEL">MODEL (jarvis.modules.facenet.face.FaceNet attribute)</a>
</li>
<li><a href="index.html#jarvis.modules.models.classes.EnvConfig.model_post_init">model_post_init() (jarvis.modules.models.classes.EnvConfig method)</a>
</li>
<li>
module
Expand Down Expand Up @@ -2868,8 +2862,6 @@ <h2 id="S">S</h2>
<li><a href="index.html#jarvis.api.routers.secure_send.secure_send_api">secure_send_api() (in module jarvis.api.routers.secure_send)</a>
</li>
<li><a href="index.html#jarvis.executors.guard.security_runner">security_runner() (in module jarvis.executors.guard)</a>
</li>
<li><a href="index.html#jarvis.modules.exceptions.SegmentationError">SegmentationError</a>
</li>
<li><a href="index.html#jarvis.modules.telegram.bot.send_audio">send_audio() (in module jarvis.modules.telegram.bot)</a>
</li>
Expand Down Expand Up @@ -3136,8 +3128,6 @@ <h2 id="T">T</h2>
<li><a href="index.html#jarvis.modules.models.classes.TemperatureUnits">TemperatureUnits (class in jarvis.modules.models.classes)</a>
</li>
<li><a href="index.html#jarvis.executors.controls.terminator">terminator() (in module jarvis.executors.controls)</a>
</li>
<li><a href="index.html#jarvis.modules.models.classes.test_and_load_audio_driver">test_and_load_audio_driver() (in module jarvis.modules.models.classes)</a>
</li>
<li><a href="index.html#tests.test_speaker.TestSpeak.test_audio_driver_usage">test_audio_driver_usage() (tests.test_speaker.TestSpeak method)</a>
</li>
Expand Down Expand Up @@ -3204,10 +3194,10 @@ <h2 id="T">T</h2>
<li><a href="index.html#module-tests.test_speech_synthesis">module</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#tests.test_speaker.TestSpeak">TestSpeak (class in tests.test_speaker)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#tests.test_speech_synthesis.TestSpeechSynthesizer">TestSpeechSynthesizer (class in tests.test_speech_synthesis)</a>
</li>
<li><a href="index.html#jarvis.modules.telegram.settings.Text">Text (class in jarvis.modules.telegram.settings)</a>
Expand Down
54 changes: 2 additions & 52 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5244,12 +5244,12 @@ <h1>———-Modules———-<a class="headerlink" href="#modules" title="Perm
<dl class="py function">
<dt class="sig sig-object py" id="jarvis.modules.audio.speaker.speak">
<span class="sig-prename descclassname"><span class="pre">jarvis.modules.audio.speaker.</span></span><span class="sig-name descname"><span class="pre">speak</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">run</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">bool</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">block</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">bool</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.modules.audio.speaker.speak" title="Permalink to this definition">¶</a></dt>
<dd><p>Calls <code class="docutils literal notranslate"><span class="pre">audio_driver.say</span></code> to speak a statement from the received text.</p>
<dd><p>Speaks a statement from the received text.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>text</strong> – Takes the text that has to be spoken as an argument.</p></li>
<li><p><strong>run</strong> – Takes a boolean flag to choose whether to run the <code class="docutils literal notranslate"><span class="pre">audio_driver.say</span></code> loop.</p></li>
<li><p><strong>run</strong> – Takes a boolean flag to choose whether to run the loop.</p></li>
<li><p><strong>block</strong> – Takes a boolean flag to await other tasks while speaking. [Applies only for speech-synthesis on docker]</p></li>
</ul>
</dd>
Expand Down Expand Up @@ -6846,32 +6846,6 @@ <h1>Crontab<a class="headerlink" href="#id3" title="Permalink to this heading">
<dd><p>alias of <a class="reference internal" href="#jarvis.modules.models.classes.SupportedPlatforms" title="jarvis.modules.models.classes.SupportedPlatforms"><code class="xref py py-class docutils literal notranslate"><span class="pre">SupportedPlatforms</span></code></a></p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="jarvis.modules.models.classes.import_module">
<span class="sig-prename descclassname"><span class="pre">jarvis.modules.models.classes.</span></span><span class="sig-name descname"><span class="pre">import_module</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.modules.models.classes.import_module" title="Permalink to this definition">¶</a></dt>
<dd><p>Instantiates pyttsx3 after importing <code class="docutils literal notranslate"><span class="pre">nsss</span></code> drivers beforehand.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="jarvis.modules.models.classes.dynamic_rate">
<span class="sig-prename descclassname"><span class="pre">jarvis.modules.models.classes.</span></span><span class="sig-name descname"><span class="pre">dynamic_rate</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">int</span></span></span><a class="headerlink" href="#jarvis.modules.models.classes.dynamic_rate" title="Permalink to this definition">¶</a></dt>
<dd><p>Speech rate based on the Operating System.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="jarvis.modules.models.classes.test_and_load_audio_driver">
<span class="sig-prename descclassname"><span class="pre">jarvis.modules.models.classes.</span></span><span class="sig-name descname"><span class="pre">test_and_load_audio_driver</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">Engine</span></span></span><a class="headerlink" href="#jarvis.modules.models.classes.test_and_load_audio_driver" title="Permalink to this definition">¶</a></dt>
<dd><p>Get audio driver by instantiating pyttsx3.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>Audio driver.</p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>pyttsx3.Engine</p>
</dd>
</dl>
</dd></dl>

<hr class="docutils" />
<dl class="py class">
<dt class="sig sig-object py" id="jarvis.modules.models.classes.SupportedPlatforms">
Expand Down Expand Up @@ -7693,21 +7667,6 @@ <h1>Crontab<a class="headerlink" href="#id3" title="Permalink to this heading">
<dd><p>Validates date value to be in DD-MM format.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="jarvis.modules.models.classes.EnvConfig.model_post_init">
<span class="sig-name descname"><span class="pre">model_post_init</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">__context</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Any</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.modules.models.classes.EnvConfig.model_post_init" title="Permalink to this definition">¶</a></dt>
<dd><p>This function is meant to behave like a BaseModel method to initialise private attributes.</p>
<p>It takes context as an argument since that’s what pydantic-core passes when calling it.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>self</strong> – The BaseModel instance.</p></li>
<li><p><strong>__context</strong> – The context.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</dd></dl>

<hr class="docutils" />
Expand Down Expand Up @@ -8141,15 +8100,6 @@ <h1>Crontab<a class="headerlink" href="#id3" title="Permalink to this heading">
</dl>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="jarvis.modules.exceptions.SegmentationError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jarvis.modules.exceptions.</span></span><span class="sig-name descname"><span class="pre">SegmentationError</span></span><a class="headerlink" href="#jarvis.modules.exceptions.SegmentationError" title="Permalink to this definition">¶</a></dt>
<dd><p>Custom <code class="docutils literal notranslate"><span class="pre">SegmentationError</span></code> raised when the code exits with SIGSEGV.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">SegmentationError</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-jarvis.modules.facenet.face">
<span id="facenet"></span><h1>FaceNet<a class="headerlink" href="#module-jarvis.modules.facenet.face" title="Permalink to this heading">¶</a></h1>
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

17 changes: 6 additions & 11 deletions jarvis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import os
from multiprocessing import current_process

version = "3.9a"
version = "3.9"

install_script = os.path.join(os.path.dirname(__file__), 'lib', 'install.sh')

try:
import cv2 # noqa: F401
import face_recognition # noqa: F401
import playsound # noqa: F401
import pvporcupine # noqa: F401
import pyaudio # noqa: F401
if current_process().name == 'MainProcess':
current_process().name = 'JARVIS'
import pynotification # noqa: F401

from ._preexec import keywords_handler # noqa: F401
from .main import start # noqa: F401
except ImportError as error:
try:
pynotification.pynotifier(title="First time user?", dialog=True, message=f"Please run\n\n{install_script}")
Expand All @@ -20,8 +20,3 @@
raise UserWarning(f"{error.__str__()}\n\nPlease run\n\n{install_script}\n\n"
"Note: Shell script will quit for any non-zero exit status, "
"so it might have to be triggered twice.")
else:
if current_process().name == 'MainProcess':
current_process().name = 'JARVIS'
from ._preexec import keywords_handler # noqa: F401
from .main import start # noqa: F401
7 changes: 2 additions & 5 deletions jarvis/executors/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ def speaker_volume(level: int) -> None:
Args:
level: Takes the volume level as an argument.
"""
if models.audio_driver:
logger.info("Jarvis' volume has been set to %d" % level + "%") # % is mandatory because of string concatenation
models.audio_driver.setProperty('volume', level / 100)
else:
logger.warning("Setting Jarvis' volume is not available for speech-synthesis")
logger.info("Jarvis' volume has been set to %d" % level + "%") # % is mandatory because of string concatenation
models.AUDIO_DRIVER.setProperty('volume', level / 100)


def volume(phrase: str = None, level: int = None) -> None:
Expand Down
14 changes: 7 additions & 7 deletions jarvis/modules/audio/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def speech_synthesizer(text: str,


def speak(text: str = None, run: bool = False, block: bool = True) -> None:
"""Calls ``audio_driver.say`` to speak a statement from the received text.
"""Speaks a statement from the received text.
Args:
text: Takes the text that has to be spoken as an argument.
run: Takes a boolean flag to choose whether to run the ``audio_driver.say`` loop.
run: Takes a boolean flag to choose whether to run the loop.
block: Takes a boolean flag to await other tasks while speaking. [Applies only for speech-synthesis on docker]
"""
if not models.audio_driver:
if not models.AUDIO_DRIVER:
models.env.speech_synthesis_timeout = 10
caller = sys._getframe(1).f_code.co_name # noqa: PyProtectedMember,PyUnresolvedReferences
if caller not in ('conditions', 'custom_conditions'): # function where all the magic happens
Expand All @@ -107,16 +107,16 @@ def speak(text: str = None, run: bool = False, block: bool = True) -> None:
os.path.isfile(models.fileio.speech_synthesis_wav):
playsound(sound=models.fileio.speech_synthesis_wav, block=block)
os.remove(models.fileio.speech_synthesis_wav)
elif models.audio_driver:
models.audio_driver.say(text=text)
elif models.AUDIO_DRIVER:
models.AUDIO_DRIVER.say(text=text)
else:
support.flush_screen()
pynotification.pynotifier(message="speech-synthesis became unavailable when audio driver was faulty\n"
"resolving to on-screen response", title="AUDIO ERROR", dialog=True)
print(text)
if run and models.audio_driver and not shared.called_by_offline:
if run and models.AUDIO_DRIVER and not shared.called_by_offline:
logger.debug("Speaker called by: '%s'", caller)
models.audio_driver.runAndWait()
models.AUDIO_DRIVER.runAndWait()


def frequently_used(function_name: str) -> None:
Expand Down
6 changes: 3 additions & 3 deletions jarvis/modules/audio/tts_stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

recognizer = Recognizer()

audio_driver = voices.voice_default()
AUDIO_DRIVER = voices.voice_default()


def text_to_audio(text: str, filename: Union[FilePath, str] = None) -> Union[FilePath, str, None]:
Expand All @@ -38,8 +38,8 @@ def text_to_audio(text: str, filename: Union[FilePath, str] = None) -> Union[Fil
shared.offline_caller = None # Reset caller after using it
else:
filename = f"{int(time.time())}.wav"
audio_driver.save_to_file(filename=filename, text=text)
audio_driver.runAndWait()
AUDIO_DRIVER.save_to_file(filename=filename, text=text)
AUDIO_DRIVER.runAndWait()
if os.path.isfile(filename) and os.stat(filename).st_size:
logger.info("Generated %s", filename)
data, samplerate = soundfile.read(file=filename)
Expand Down
8 changes: 4 additions & 4 deletions jarvis/modules/audio/voices.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def voice_default() -> Engine:
if voice.name == models.env.voice_name or models.env.voice_name in voice.name:
if models.settings.pname == 'JARVIS':
logger.debug(voice.__dict__)
models.audio_driver.setProperty("voice", voice.id)
models.audio_driver.setProperty("rate", models.env.speech_rate)
models.AUDIO_DRIVER.setProperty("voice", voice.id)
models.AUDIO_DRIVER.setProperty("rate", models.env.speech_rate)
break
return models.audio_driver
return models.AUDIO_DRIVER


def voice_changer(phrase: str = None) -> None:
Expand All @@ -50,7 +50,7 @@ def voice_changer(phrase: str = None) -> None:
"How about this one?"]

for ind, voice in enumerate(models.voices):
models.audio_driver.setProperty("voice", models.voices[ind].id)
models.AUDIO_DRIVER.setProperty("voice", models.voices[ind].id)
speaker.speak(text=f"I am {voice.name} {models.env.title}!")
support.write_screen(f"Voice module has been re-configured to {ind}::{voice.name}")
if ind < len(choices_to_say):
Expand Down
8 changes: 0 additions & 8 deletions jarvis/modules/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,6 @@ def __str__(self) -> str:
return repr(self.msg)


class SegmentationError(EnvironmentError):
"""Custom ``SegmentationError`` raised when the code exits with SIGSEGV.
>>> SegmentationError
"""


CONDITIONAL_ENDPOINT_RESTRICTION = APIResponse(
status_code=HTTPStatus.NOT_IMPLEMENTED.real,
detail="Required environment variables have not been setup.\nPlease refer: "
Expand Down
Loading

0 comments on commit 2ebd589

Please sign in to comment.