You would need compile it into the app. Which is not be possible without the source code to Pythonista. You would be able to do it with Pyto which is open source but it would be complicated.
You are right. With the AppStore version of both apps is not possible, I need to compile my own, at least can test it with Pyto.
In my last approach I ended by compiling a test
Clibrary for arm64 and then I signed it with
Pythonistaapparently accept the dynamic library but stops importing it as the identity used to signed it is not the same of the identity the owner of the app used (or at least that is what I think, really don’t know which other thing is preventing to load it)
If you are interested in reading the traceback of
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/HIDDEN/Pythonista3/Documents/hw.py", line 4, in <module> test_lib = ctypes.cdll.LoadLibrary("./test-lib_1.so") File "/var/containers/Bundle/Application/HIDDEN/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/ctypes/__init__.py", line 427, in LoadLibrary return self._dlltype(name) File "/var/containers/Bundle/Application/HIDDEN/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/ctypes/__init__.py", line 349, in __init__ self._handle = _dlopen(self._name, mode) OSError: dlopen(/private/var/mobile/Containers/Shared/AppGroup/HIDDEN/Pythonista3/Documents/test-lib_1.so, 0x0006): code signature invalid (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x00008050, codeBlobSize=0x00004900 for '/private/var/mobile/Containers/Shared/AppGroup/HIDDEN/Pythonista3/Documents/test-lib_1.so'
How apple encapsulates the apps is very interesting and I still believe that someone super skilled can archive this, anyway, thanks again @ccc for your quick answer
Hello everyone, I have this stupid question that has a high chance of receive a NO as answer.
First the background.
Recently I have testing the python feature of importing code written in C and compiled into dynamic libraries
.sofiles on my PC, In my tests I could notice that I can import files with only the read and write permissions, so base on that I conclude that I don't need the execution permission in that kind of file to import them to python.
All of those tests where made approaching
import ctypes my_c_library = ctypes.cdll.LoadLibrary("/path/to/library") my_c_library.my_c_function(arg_1, arg_2)
Now that I have access to a Mac I was trying to approach the
Xcodetools to compile a dynamic library and import it to Pythonista, the problem is that it is extremely hard to setup the environment for the compilation to
iOS, I mean, I could compile to
arm64but looks like
iOShas other libraries that I have no access to (or at least I don't know where to find them)
If anyone have a solution or have an alternative way to approach something similar I really will appreciate it
@ihf check this and try something similar to check if it works https://stackoverflow.com/questions/15750711/connecting-to-sql-server-2012-using-sqlalchemy-and-pyodbc
I think that erasing a Pythonista build-in module is not possible, remember that python has a weird importing system so if you have a script/folder called speech in the same folder of your main script maybe you are importing it instead of the build in one. (python import order is: current dir, ... , site-packages, build-in) but If that is not the case, I think a fresh install of Pythonista could work
import objc_util import re class SpeechModule(object): def __init__(self): self.__AVSpeechUtterance = objc_util.ObjCClass('AVSpeechUtterance') self.__AVSpeechSynthesizer = objc_util.ObjCClass('AVSpeechSynthesizer') self.__AVSpeechSynthesisVoice = objc_util.ObjCClass('AVSpeechSynthesisVoice') self.__synthesizer = self.__AVSpeechSynthesizer.new() def get_synthesis_languages(self) -> list: return self.__AVSpeechSynthesisVoice.speechVoices() def say(self, msg: str, language: objc_util.ObjCInstance, rate=0.5): utterance = self.__AVSpeechUtterance.speechUtteranceWithString_(msg) utterance.rate = rate utterance.voice = voice utterance.useCompactVoice = False self.__synthesizer.speakUtterance_(utterance) def is_speaking(self) -> bool: return self.__synthesizer.isSpeaking() def is_paused(self) -> bool: return self.__synthesizer.isPaused() def pause(self) -> bool: return self.__synthesizer.pauseSpeakingAtBoundary_(True) def stop(self) -> bool: return self.__synthesizer.stopSpeakingAtBoundary_(True) def continue_speaking(self): self.__synthesizer.continueSpeaking()
Here is an example how to use it
import time speech_ = SpeechModule() available_voices = speech_.get_synthesis_languages() us_english_voices = tuple(filter(lambda voice: "en-US" in str(voice), available_voices)) voice = us_english_voices speech_.say('Hello friend! how are you?', voice, 0.3) time.sleep(1) speech_.stop() print(speech_.is_speaking()) speech_.say("nevermind", voice)