issue150:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue150:python [2019/10/31 08:26] – auntiee | issue150:python [2019/10/31 16:29] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | 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" | + | **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' | + | 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' |
- | Now let's start with this month' | + | HELLO WORLD ! Je hais l' |
+ | |||
+ | Vous avez pu noter ci-dessus que cet article est le 98e de la série sur la programmation en Python. Si tout se passe comme prévu, mon 100e article sera dans le magazine Full Circle de décembre. | ||
+ | |||
+ | **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. | 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. | + | 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.** |
- | The best that I could find that fits all those requirements is a package called eSpeak (https:// | + | Commençons maintenant l'article de ce mois ... la raison pour laquelle vous lisez ceci... |
- | How to use it... | + | 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. | Luckily, to install eSpeak-ng on Ubuntu is pretty easy. | ||
Ligne 21: | Ligne 33: | ||
:~$ espeak-ng " | :~$ 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. | + | 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:// | + | **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: | If you want to see the various languages that are available, just type: | ||
Ligne 31: | Ligne 55: | ||
You will receive the output shown on the next page (top right). | 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' | + | I've cut that list down considerably to save space here in the article. And to be brutally honest, I wouldn' |
- | To use a specific voice, such as Spanish, you can use: | + | 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 " | :~$ espeak-ng -ves " | ||
Ligne 43: | Ligne 77: | ||
Another thing that we can do is to change the pitch using the -p < | 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 75 " | ||
:~$ espeak-ng -ves -s 125 -p 35 " | :~$ espeak-ng -ves -s 125 -p 35 " | ||
- | That's fine for the command-line, | + | **That's fine for the command-line, |
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:// | 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:// | ||
Ligne 58: | Ligne 106: | ||
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... | 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 instantiate the engine: |
>>> | >>> | ||
Ligne 76: | Ligne 138: | ||
>>> | >>> | ||
- | >>> | + | >>> |
- | Now, let's change the pitch as we did before. The syntax is a bit different, but still simple: | + | 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: | ||
>>> | >>> | ||
Ligne 84: | Ligne 164: | ||
What if we want to find our the current speed or pitch? Just this 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 : | ||
>>> | >>> | ||
Ligne 95: | Ligne 192: | ||
175 | 175 | ||
- | Even finding out the current voice is simple: | + | **Even finding out the current voice is simple: |
>>> | >>> | ||
Ligne 107: | Ligne 204: | ||
(output is below) | (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. | + | Many more options are available, and you can pretty much use everything shown above to figure out how to carry on from here.** |
- | Now there is one other Text to Speech option that we have available to us. The reason I haven' | + | 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 | :~$ sudo apt-get install sox libsox-fmt-mp3 | ||
Ligne 118: | Ligne 229: | ||
Once we have that done, let's try it on the command-line. | 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)" | :~$ 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', | + | **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:// | There is a small amount of documentation available at https:// | ||
Ligne 129: | Ligne 252: | ||
Now, let's look at google_speech in Python. | 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. | ||
>>> | >>> | ||
Ligne 136: | Ligne 273: | ||
>>> | >>> | ||
- | And now for something completely different... | + | **And now for something completely different... |
>>> | >>> | ||
Ligne 143: | Ligne 280: | ||
>>> | >>> | ||
- | 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:// | + | 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=" | <say-as interpret-as=" | ||
</ | </ | ||
Ligne 151: | Ligne 297: | ||
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. | 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! | + | 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.1572506760.txt.gz · Dernière modification : 2019/10/31 08:26 de auntiee