Oreille

A small week end project: Oreille is a wrapper on OpenAPI Whisper API. It provides support for long audio files.

OpenAPI Whisper support only files that are less than 25 MB. Oreille will break the audio file into chunks of 25 MB’s or less. https://platform.openai.com/docs/guides/speech-to-text/longer-inputs

Oreille will also compute the correct timing of the subtitle when merging the output of Whisper. So once you export the subtitle the timestamp of the subtitle will be right.

You can open and save WAV files with pure python. For opening and saving non-wav files – like mp3 – you’ll need ffmpeg or libav.

View project on Github

JSONApiDoc

JSON Api Doc une petite bibliothèque Open Source que j’ai publiée. En manipulant des API en JSON API une chose m’a beaucoup gêné. L’utilisation des included pour éviter de dupliquer les données rend la lecture très difficile par un humain. Cette bibliothèque utilisable dans un programme Python ou en cli permet tout simplement de résoudre les included et de renvoyer un objet plus simple à lire et à manipuler par un humain.

Read more...

Detect Python code duplicate

You can detect Python code duplicate with Pylint pylint --disable=all --enable=duplicate-code src/ No config file found, using default configuration ************* Module gns3server.compute.dynamips.nodes.ethernet_switch R: 1, 0: Similar lines in 2 files ==gns3server.compute.dynamips.nodes.ethernet_hub:101 ==gns3server.compute.dynamips.nodes.ethernet_switch:136 @property def mappings(self): """ Returns port mappings :returns: mappings list """ return self._mappings @asyncio.coroutine def delete(self): return (yield from self.close()) @asyncio.coroutine def close(self): """ Deletes this hub. """ (duplicate-code) R: 1, 0: Similar lines in 2 files ==gns3server.compute.dynamips.nodes.ethernet_hub:66 ==gns3server.

Read more...

Migration from PyQT4 to PyQT5 at GNS3

The current GNS3 GUI interface use PyQT4. In order to support the retina display we choose to move to PyQT5. The move was not too complicated with the help of a small script. You can see the complete list of PyQT4 / PyQT5 differences here: http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html Actually most of recent distributions support PyQT5: Debian Jessie Ubuntu 14.04 and later Arch linux Gentoo Fedora 21 and later In all our code we already not directly include the PyQT4 module but our own qt module responsible of all the imports this save us the need to patch every files for changing the module.

Read more...

Asyncio blocking code

Asyncio is greats piece of software. But all Python code is not compatible. In the following example we will see how to run blocking code from your asyncio code. We will by a simple asyncio application: import asyncio import time @asyncio.coroutine def clock(): while True: print("Current time from asynchronous code: {}".format(int(time.time()))) yield from asyncio.sleep(1) def main(): loop = asyncio.get_event_loop() asyncio.async(clock()) loop.run_forever() if __name__ == '__main__': main() The output is: Current time from asynchronous code: 1422265105 Current time from asynchronous code: 1422265106 And add blocking code:

Read more...

PEP 8 Git pre commit hook

This pre commit hook will check the PEP8 syntax of your Python files and ask you if you want to continue the commit process. In your project directory create a file: .git/hooks/pre-commit and add the execution permission on it. #!/bin/bash echo "Pre-commit started" echo "PEP 8 check" git diff --cached --name-only | grep .py | xargs pep8 if [ $? == 0 ] then exit 0 fi # Allows us to read user input below, assigns stdin to keyboard exec < /dev/tty echo "Do you want to ignore warning?

Read more...

Lire les IPTC en Python

Pour récupérer les IPTC en Python vous avez plusieurs choix dont PIL. Le support des IPTC de PIL étant incomplet je me suis rabattu sur le module IPTCInfo. Voici un exemple d’utilisation: from iptcinfo import IPTCInfo import sys info = IPTCInfo('test.jpg') # Affiche la liste des mots clef print info.keywords

Tester l'existence d'une variable en Python

Lorsque l’on débarque de langage plus permissif que Python comme PHP ou Perl on est surpris lorsqu’en essayant de tester l’existence d’une variable avec un simple if le programme s’arrete. if toto: print toto Traceback (most recent call last): File "./test.py", line 4, in ? if toto: NameError: name 'toto' is not defined En Python on part du principe qu’il est plus facile de demander pardon que de d’obtenir la permission.

Read more...