issue150:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue150:python [2019/10/29 19:07] – créée d52fr | issue150:python [2019/10/31 16:29] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Traduction | + | **HELLO WORLD! I hate using that phrase when introducing someone to a new programming language or concept; so much in fact, I refuse to use it. I change it to something like "Hello from Python" |
+ | |||
+ | You might notice above that this is article # 98 in my Python programming series. If everything goes according to plan, my 100th article will in December' | ||
+ | |||
+ | HELLO WORLD ! Je hais l' | ||
+ | |||
+ | Vous avez pu noter ci-dessus que cet article est le 98e de la série | ||
+ | |||
+ | **Now let's start with this month' | ||
+ | |||
+ | Text to Speech. Something that has been around for many years, but when it comes to Linux, is fairly limited, especially when it comes to free software. Add a requirement of Python usage to that and the list gets shorter, so let's explore what's out there. Another requirement is that it needs to be something that is somewhat regularly maintained, and it needs to have some documentation that a normal person can really understand. | ||
+ | |||
+ | Remember, as we are going through this, the old saying "You get what you pay for" and in this instance it's true to some extent.** | ||
+ | |||
+ | Commençons maintenant l' | ||
+ | |||
+ | De l' | ||
+ | |||
+ | Souvenez-vous, | ||
+ | |||
+ | **The best that I could find that fits all those requirements is a package called eSpeak (https:// | ||
+ | |||
+ | Le mieux que j'ai pu trouver qui correspond à toutes ces exigences est un paquet appelé eSpeak (https:// | ||
+ | |||
+ | **How to use it... | ||
+ | |||
+ | Luckily, to install eSpeak-ng on Ubuntu is pretty easy. | ||
+ | |||
+ | :~$ sudo apt-get install espeak-ng-espeak | ||
+ | |||
+ | To test it, while you are in the terminal, try this... | ||
+ | |||
+ | :~$ espeak-ng " | ||
+ | |||
+ | Now you can hear what I'm talking about. It's pretty much robotic and something reminds you of listening to the voice of Stephen Hawking. If you listen carefully, it can be mostly understood.** | ||
+ | |||
+ | Comment l' | ||
+ | |||
+ | Par chance, l' | ||
+ | |||
+ | :~$ sudo apt-get install espeak-ng-espeak | ||
+ | |||
+ | Pour le tester, quand vous êtes dans un terminal, essayez ceci : | ||
+ | |||
+ | :~$ espeak-ng « Bienvenue dans le traitement de l' | ||
+ | |||
+ | Maintenant, vous pouvez entendre ce dont je parlais. C'est vraiment mécanique et ça vous rappelle quelque peu la voix de Stephen Hawking. Si vous écoutez avec attention, c'est presque entièrement compréhensible. | ||
+ | |||
+ | **There are many command-line arguments that you can use to change things around and to provide other options. A quick documentation page is at https:// | ||
+ | |||
+ | If you want to see the various languages that are available, just type: | ||
+ | |||
+ | :~$ espeak-ng --voices | ||
+ | |||
+ | You will receive the output shown on the next page (top right). | ||
+ | |||
+ | I've cut that list down considerably to save space here in the article. And to be brutally honest, I wouldn' | ||
+ | |||
+ | Il existe de nombreux arguments en ligne de commande que vous pouvez utiliser pour modifier les choses et qui fournissent d' | ||
+ | |||
+ | Si vous voulez voir les différentes langues disponibles, | ||
+ | |||
+ | :~$ espeak-ng --voices | ||
+ | |||
+ | Vous recevrez la réponse présentée à la page suivante (en haut à droite). | ||
+ | |||
+ | J'ai considérablement réduit cette liste pour économiser la place dans cet article. Et pour être très franc, je suis incapable de dire si certains d' | ||
+ | |||
+ | **To use a specific voice, such as Spanish, you can use: | ||
+ | |||
+ | :~$ espeak-ng -ves " | ||
+ | |||
+ | We can also change the speed of the vocal output by using the -s < | ||
+ | |||
+ | :~$ espeak-ng -ves -s 125 " | ||
+ | :~$ espeak-ng -ves -s 90 " | ||
+ | |||
+ | Another thing that we can do is to change the pitch using the -p < | ||
+ | |||
+ | :~$ espeak-ng -ves -s 125 -p 75 " | ||
+ | :~$ espeak-ng -ves -s 125 -p 35 " | ||
+ | |||
+ | Pour utiliser une voix particulière, | ||
+ | |||
+ | :~$ espeak-ng -ves " | ||
+ | |||
+ | Nous pouvons aussi modifier la vitesse de la sortie vocale en utilisant l' | ||
+ | |||
+ | :~$ espeak-ng -ves -s 125 " | ||
+ | :~$ espeak-ng -ves -s 90 " | ||
+ | |||
+ | Autre chose : vous pouvez modifier la hauteur (pitch) en utilisant l' | ||
+ | |||
+ | :~$ espeak-ng -ves -s 125 -p 75 " | ||
+ | :~$ espeak-ng -ves -s 125 -p 35 " | ||
+ | |||
+ | **That' | ||
+ | |||
+ | We need a library to interface with eSpeak-ng. Luckily, there is a pretty nice version that can be installed via pip. It's called py-espeak-ng. It works on both Python 2.x and 3.x . The homepage is https:// | ||
+ | |||
+ | pip install py-espeak-ng | ||
+ | |||
+ | or | ||
+ | |||
+ | pip3 install py-espeak-ng | ||
+ | |||
+ | Once py-espeak-ng is installed, fire up your favorite version of Python. The documentation shows a slightly different sequence of commands, but they don't work on my system. This sequence does… The first thing we have to do is import the library... | ||
+ | |||
+ | >>> | ||
+ | |||
+ | C'est bien en ligne de commande, mais ce que nous voulons, c'est pouvoir créer la parole depuis un programme en Python. Pas de problème. | ||
+ | |||
+ | Nous avons besoin d'une bibliothèque qui s' | ||
+ | |||
+ | pip install py-espeak-ng | ||
+ | |||
+ | ou | ||
+ | |||
+ | pip3 install py-espeak-ng | ||
+ | |||
+ | Une fois py-espeak-ng installée, lancez votre version préférée de Python. La documentation montre une séquence de commandes légèrement différente, | ||
+ | |||
+ | >>> | ||
+ | |||
+ | **Next, we need to instantiate the engine: | ||
+ | |||
+ | >>> | ||
+ | |||
+ | Next, we need to assign a voice... | ||
+ | |||
+ | >>> | ||
+ | |||
+ | Now we can finally have the engine speak to us... | ||
+ | |||
+ | >>> | ||
+ | |||
+ | Now, let's change the voice, this time to French: | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | Ensuite, nous devons instancier le moteur : | ||
+ | |||
+ | >>> | ||
+ | |||
+ | Puis, nous avons besoin d' | ||
+ | |||
+ | >>> | ||
+ | |||
+ | Maintenant, nous disposons enfin d'un moteur qui peut nous parler : | ||
+ | |||
+ | >>> | ||
+ | |||
+ | Changeons la voix, cette fois en français : | ||
+ | |||
+ | >>> | ||
+ | |||
+ | >>> | ||
+ | |||
+ | **Now, let's change the pitch as we did before. The syntax is a bit different, but still simple: | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | What if we want to find our the current speed or pitch? Just this simple... | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | 32 | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | 175** | ||
+ | |||
+ | Maintenant, changeons la hauteur, comme nous l' | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | Et que se passe-t-il si nous voulons connaître la vitesse ou la hauteur actuelle ? Rien de plus simple : | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | 32 | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | 175 | ||
+ | |||
+ | **Even finding out the current voice is simple: | ||
+ | |||
+ | >>> | ||
+ | |||
+ | fr | ||
+ | |||
+ | To get the list of voices: | ||
+ | |||
+ | >>> | ||
+ | |||
+ | (output is below) | ||
+ | |||
+ | Many more options are available, and you can pretty much use everything shown above to figure out how to carry on from here.** | ||
+ | |||
+ | C'est même facile de trouver la voix actuelle : | ||
+ | |||
+ | >>> | ||
+ | |||
+ | fr | ||
+ | |||
+ | Pour obtenir la liste des voix : | ||
+ | |||
+ | >>> | ||
+ | |||
+ | (La sortie est ci-dessous.) | ||
+ | |||
+ | Beaucoup d' | ||
+ | |||
+ | **Now there is one other Text to Speech option that we have available to us. The reason I haven' | ||
+ | |||
+ | :~$ sudo apt-get install sox libsox-fmt-mp3 | ||
+ | |||
+ | Next, install the google_speech library using pip: | ||
+ | |||
+ | :~$ pip3 install google_speech | ||
+ | |||
+ | Once we have that done, let's try it on the command-line. | ||
+ | |||
+ | :~$ google_speech -l en "Hello $USER, it is $(date)" | ||
+ | |||
+ | En fait, une autre option Écrit vers oral existe et est disponible. Je ne l'ai pas mentionnée jusqu' | ||
+ | |||
+ | :~$ sudo apt-get install sox libsox-fmt-mp3 | ||
+ | |||
+ | Ensuite, installez la bibliothèque google_speech en utilisant pip : | ||
+ | |||
+ | :~$ pip3 install google_speech | ||
+ | |||
+ | Une fois que nous l' | ||
+ | |||
+ | :~$ google_speech -l en "Hello $USER, it is $(date)" | ||
+ | |||
+ | **For some reason I get 'sox WARN alsa: can't encode 0-bit Unknown or not applicable', | ||
+ | |||
+ | There is a small amount of documentation available at https:// | ||
+ | |||
+ | You can even try the code shown above. | ||
+ | |||
+ | Now, let's look at google_speech in Python. | ||
+ | |||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | Pour une raison indéterminée, | ||
+ | |||
+ | Il a une petite quantité de documentation disponible sur https:// | ||
+ | |||
+ | Vous pouvez même essayer le code ci-dessus. | ||
+ | |||
+ | Maintenant, regardons google_speech dans Python. | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | **And now for something completely different... | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | You can certainly see that the speech is much better and more understandable. Why not stick with this? One of the requirements I stated earlier was that it needed to be free. That not only applies to the software that we use, but the engine service and the lack of internet. If these last two don't bother you, then this is for you. You do, however need to be aware of the cost of using the Google API for this. According to https:// | ||
+ | |||
+ | Et maintenant, pour quelque chose de complètement différent : | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | Vous pouvez certainement voir que la parole est de meilleure qualité et plus compréhensible. Pourquoi ne pas rester avec ce logiciel-là ? Une des exigences que j'ai affirmée plus tôt était qu'il fallait que ce soit libre. Ça ne s' | ||
+ | |||
+ | **< | ||
+ | <say-as interpret-as=" | ||
+ | </ | ||
+ | |||
+ | would count as 79 characters. So be careful when you attempt to calculate your usage. There is also the possibility that if you send too much data too quickly, the system might block you for a while if you don't have an account. | ||
+ | |||
+ | Well, that’s about it for this month. Until next time, keep coding! ** | ||
+ | |||
+ | < | ||
+ | <say-as interpret-as=" | ||
+ | and one more | ||
+ | </ | ||
+ | |||
+ | 79 caractères seront comptés. Aussi, soyez prudent si vous cherchez à calculer votre utilisation. Il est aussi possible que, si vous envoyez trop de données trop rapidement, le système puisse vous bloquer pendant un moment si vous n'avez pas de compte. | ||
+ | |||
+ | Bon. Ce sera tout pour ce mois-ci. Jusqu' | ||
+ |
issue150/python.1572372460.txt.gz · Dernière modification : 2019/10/29 19:07 de d52fr