How to use supported_features method in lisa

Best Python code snippet using lisa_python

Text-to-Speech.py

Source:Text-to-Speech.py Github

copy

Full Screen

1{2 "cells": [3 {4 "cell_type": "code",5 "execution_count": 7,6 "metadata": {},7 "outputs": [],8 "source": [9 "# Documentation: https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices"10 ]11 },12 {13 "cell_type": "markdown",14 "metadata": {},15 "source": [16 "# 0. Install Dependencies"17 ]18 },19 {20 "cell_type": "code",21 "execution_count": 1,22 "metadata": {23 "collapsed": true24 },25 "outputs": [26 {27 "name": "stdout",28 "output_type": "stream",29 "text": [30 "Requirement already satisfied: ibm_watson in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (4.5.0)\n",31 "Requirement already satisfied: python-dateutil>=2.5.3 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from ibm_watson) (2.8.0)\n",32 "Requirement already satisfied: requests<3.0,>=2.0 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from ibm_watson) (2.22.0)\n",33 "Requirement already satisfied: websocket-client==0.48.0 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from ibm_watson) (0.48.0)\n",34 "Requirement already satisfied: ibm-cloud-sdk-core==1.5.1 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from ibm_watson) (1.5.1)\n",35 "Requirement already satisfied: six>=1.5 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from python-dateutil>=2.5.3->ibm_watson) (1.12.0)\n",36 "Requirement already satisfied: idna<2.9,>=2.5 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from requests<3.0,>=2.0->ibm_watson) (2.8)\n",37 "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from requests<3.0,>=2.0->ibm_watson) (1.24.2)\n",38 "Requirement already satisfied: certifi>=2017.4.17 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from requests<3.0,>=2.0->ibm_watson) (2019.9.11)\n",39 "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from requests<3.0,>=2.0->ibm_watson) (3.0.4)\n",40 "Requirement already satisfied: PyJWT>=1.7.1 in /Users/nicholasrenotte/opt/anaconda3/lib/python3.7/site-packages (from ibm-cloud-sdk-core==1.5.1->ibm_watson) (1.7.1)\n"41 ]42 }43 ],44 "source": [45 "!pip install ibm_watson"46 ]47 },48 {49 "cell_type": "markdown",50 "metadata": {},51 "source": [52 "# 1. Authenticate"53 ]54 },55 {56 "cell_type": "code",57 "execution_count": 2,58 "metadata": {},59 "outputs": [],60 "source": [61 "from ibm_watson import TextToSpeechV1\n",62 "from ibm_cloud_sdk_core.authenticators import IAMAuthenticator"63 ]64 },65 {66 "cell_type": "code",67 "execution_count": 3,68 "metadata": {},69 "outputs": [],70 "source": [71 "apikey = 'YOUR API KEY'\n",72 "url = 'YOUR SERVICE URL'"73 ]74 },75 {76 "cell_type": "code",77 "execution_count": 6,78 "metadata": {},79 "outputs": [],80 "source": [81 "# Setup Service\n",82 "authenticator = IAMAuthenticator(apikey)\n",83 "tts = TextToSpeechV1(authenticator=authenticator)\n",84 "tts.set_service_url(url)"85 ]86 },87 {88 "cell_type": "markdown",89 "metadata": {},90 "source": [91 "## 2. Convert with A Basic Language Model"92 ]93 },94 {95 "cell_type": "code",96 "execution_count": 9,97 "metadata": {},98 "outputs": [],99 "source": [100 "with open('./speech.mp3', 'wb') as audio_file:\n",101 " res = tts.synthesize('Hello World!', accept='audio/mp3', voice='en-US_AllisonV3Voice').get_result()\n",102 " audio_file.write(res.content)"103 ]104 },105 {106 "cell_type": "markdown",107 "metadata": {},108 "source": [109 "## 3. Reading from a File "110 ]111 },112 {113 "cell_type": "code",114 "execution_count": 28,115 "metadata": {},116 "outputs": [],117 "source": [118 "with open('churchill.txt', 'r') as f:\n",119 " text = f.readlines()"120 ]121 },122 {123 "cell_type": "code",124 "execution_count": 36,125 "metadata": {},126 "outputs": [],127 "source": [128 "text = [line.replace('\\n','') for line in text]"129 ]130 },131 {132 "cell_type": "code",133 "execution_count": 39,134 "metadata": {},135 "outputs": [],136 "source": [137 "text = ''.join(str(line) for line in text)"138 ]139 },140 {141 "cell_type": "code",142 "execution_count": 40,143 "metadata": {},144 "outputs": [],145 "source": [146 "with open('./winston.mp3', 'wb') as audio_file:\n",147 " res = tts.synthesize(text, accept='audio/mp3', voice='en-GB_JamesV3Voice').get_result()\n",148 " audio_file.write(res.content)"149 ]150 },151 {152 "cell_type": "markdown",153 "metadata": {},154 "source": [155 "## 4. Convert with a Different Language Model"156 ]157 },158 {159 "cell_type": "markdown",160 "metadata": {},161 "source": [162 "# Effects of adding Punctuation"163 ]164 },165 {166 "cell_type": "code",167 "execution_count": 16,168 "metadata": {169 "collapsed": true170 },171 "outputs": [172 {173 "name": "stdout",174 "output_type": "stream",175 "text": [176 "{\n",177 " \"voices\": [\n",178 " {\n",179 " \"gender\": \"female\",\n",180 " \"supported_features\": {\n",181 " \"custom_pronunciation\": true,\n",182 " \"voice_transformation\": false\n",183 " },\n",184 " \"name\": \"en-US_LisaV2Voice\",\n",185 " \"customizable\": true,\n",186 " \"description\": \"Lisa: American English female voice. Dnn technology.\",\n",187 " \"language\": \"en-US\",\n",188 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_LisaV2Voice\"\n",189 " },\n",190 " {\n",191 " \"gender\": \"female\",\n",192 " \"supported_features\": {\n",193 " \"custom_pronunciation\": true,\n",194 " \"voice_transformation\": false\n",195 " },\n",196 " \"name\": \"de-DE_BirgitV3Voice\",\n",197 " \"customizable\": true,\n",198 " \"description\": \"Birgit: Standard German (Standarddeutsch) female voice. Dnn technology.\",\n",199 " \"language\": \"de-DE\",\n",200 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/de-DE_BirgitV3Voice\"\n",201 " },\n",202 " {\n",203 " \"gender\": \"female\",\n",204 " \"supported_features\": {\n",205 " \"custom_pronunciation\": true,\n",206 " \"voice_transformation\": false\n",207 " },\n",208 " \"name\": \"es-LA_SofiaVoice\",\n",209 " \"customizable\": true,\n",210 " \"description\": \"Sofia: Latin American Spanish (espa\\u00f1ol latinoamericano) female voice.\",\n",211 " \"language\": \"es-LA\",\n",212 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/es-LA_SofiaVoice\"\n",213 " },\n",214 " {\n",215 " \"gender\": \"female\",\n",216 " \"supported_features\": {\n",217 " \"custom_pronunciation\": true,\n",218 " \"voice_transformation\": false\n",219 " },\n",220 " \"name\": \"en-US_LisaV3Voice\",\n",221 " \"customizable\": true,\n",222 " \"description\": \"Lisa: American English female voice. Dnn technology.\",\n",223 " \"language\": \"en-US\",\n",224 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_LisaV3Voice\"\n",225 " },\n",226 " {\n",227 " \"gender\": \"female\",\n",228 " \"supported_features\": {\n",229 " \"custom_pronunciation\": true,\n",230 " \"voice_transformation\": false\n",231 " },\n",232 " \"name\": \"fr-FR_ReneeV3Voice\",\n",233 " \"customizable\": true,\n",234 " \"description\": \"Renee: French (fran\\u00e7ais) female voice. Dnn technology.\",\n",235 " \"language\": \"fr-FR\",\n",236 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/fr-FR_ReneeV3Voice\"\n",237 " },\n",238 " {\n",239 " \"gender\": \"male\",\n",240 " \"supported_features\": {\n",241 " \"custom_pronunciation\": true,\n",242 " \"voice_transformation\": false\n",243 " },\n",244 " \"name\": \"en-US_KevinV3Voice\",\n",245 " \"customizable\": true,\n",246 " \"description\": \"Kevin: American English male voice. Dnn technology.\",\n",247 " \"language\": \"en-US\",\n",248 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_KevinV3Voice\"\n",249 " },\n",250 " {\n",251 " \"gender\": \"female\",\n",252 " \"supported_features\": {\n",253 " \"custom_pronunciation\": true,\n",254 " \"voice_transformation\": false\n",255 " },\n",256 " \"name\": \"en-US_AllisonV2Voice\",\n",257 " \"customizable\": true,\n",258 " \"description\": \"Allison: American English female voice. Dnn technology.\",\n",259 " \"language\": \"en-US\",\n",260 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_AllisonV2Voice\"\n",261 " },\n",262 " {\n",263 " \"gender\": \"female\",\n",264 " \"supported_features\": {\n",265 " \"custom_pronunciation\": true,\n",266 " \"voice_transformation\": false\n",267 " },\n",268 " \"name\": \"de-DE_ErikaV3Voice\",\n",269 " \"customizable\": true,\n",270 " \"description\": \"Erika: Standard German (Standarddeutsch) female voice. Dnn technology.\",\n",271 " \"language\": \"de-DE\",\n",272 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/de-DE_ErikaV3Voice\"\n",273 " },\n",274 " {\n",275 " \"gender\": \"female\",\n",276 " \"supported_features\": {\n",277 " \"custom_pronunciation\": true,\n",278 " \"voice_transformation\": false\n",279 " },\n",280 " \"name\": \"ja-JP_EmiV3Voice\",\n",281 " \"customizable\": true,\n",282 " \"description\": \"Emi: Japanese (\\u65e5\\u672c\\u8a9e) female voice. Dnn technology.\",\n",283 " \"language\": \"ja-JP\",\n",284 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/ja-JP_EmiV3Voice\"\n",285 " },\n",286 " {\n",287 " \"gender\": \"female\",\n",288 " \"supported_features\": {\n",289 " \"custom_pronunciation\": true,\n",290 " \"voice_transformation\": false\n",291 " },\n",292 " \"name\": \"it-IT_FrancescaV2Voice\",\n",293 " \"customizable\": true,\n",294 " \"description\": \"Francesca: Italian (italiano) female voice. Dnn technology.\",\n",295 " \"language\": \"it-IT\",\n",296 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/it-IT_FrancescaV2Voice\"\n",297 " },\n",298 " {\n",299 " \"gender\": \"male\",\n",300 " \"supported_features\": {\n",301 " \"custom_pronunciation\": true,\n",302 " \"voice_transformation\": false\n",303 " },\n",304 " \"name\": \"de-DE_DieterV2Voice\",\n",305 " \"customizable\": true,\n",306 " \"description\": \"Dieter: Standard German (Standarddeutsch) male voice. Dnn technology.\",\n",307 " \"language\": \"de-DE\",\n",308 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/de-DE_DieterV2Voice\"\n",309 " },\n",310 " {\n",311 " \"gender\": \"male\",\n",312 " \"supported_features\": {\n",313 " \"custom_pronunciation\": true,\n",314 " \"voice_transformation\": false\n",315 " },\n",316 " \"name\": \"en-US_HenryV3Voice\",\n",317 " \"customizable\": true,\n",318 " \"description\": \"Henry: American English male voice. Dnn technology.\",\n",319 " \"language\": \"en-US\",\n",320 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_HenryV3Voice\"\n",321 " },\n",322 " {\n",323 " \"gender\": \"female\",\n",324 " \"supported_features\": {\n",325 " \"custom_pronunciation\": true,\n",326 " \"voice_transformation\": false\n",327 " },\n",328 " \"name\": \"de-DE_BirgitV2Voice\",\n",329 " \"customizable\": true,\n",330 " \"description\": \"Birgit: Standard German (Standarddeutsch) female voice. Dnn technology.\",\n",331 " \"language\": \"de-DE\",\n",332 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/de-DE_BirgitV2Voice\"\n",333 " },\n",334 " {\n",335 " \"gender\": \"female\",\n",336 " \"supported_features\": {\n",337 " \"custom_pronunciation\": true,\n",338 " \"voice_transformation\": false\n",339 " },\n",340 " \"name\": \"pt-BR_IsabelaV3Voice\",\n",341 " \"customizable\": true,\n",342 " \"description\": \"Isabela: Brazilian Portuguese (portugu\\u00eas brasileiro) female voice. Dnn technology.\",\n",343 " \"language\": \"pt-BR\",\n",344 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/pt-BR_IsabelaV3Voice\"\n",345 " },\n",346 " {\n",347 " \"gender\": \"female\",\n",348 " \"supported_features\": {\n",349 " \"custom_pronunciation\": true,\n",350 " \"voice_transformation\": false\n",351 " },\n",352 " \"name\": \"en-US_EmilyV3Voice\",\n",353 " \"customizable\": true,\n",354 " \"description\": \"Emily: American English female voice. Dnn technology.\",\n",355 " \"language\": \"en-US\",\n",356 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_EmilyV3Voice\"\n",357 " },\n",358 " {\n",359 " \"gender\": \"female\",\n",360 " \"supported_features\": {\n",361 " \"custom_pronunciation\": true,\n",362 " \"voice_transformation\": false\n",363 " },\n",364 " \"name\": \"en-US_AllisonV3Voice\",\n",365 " \"customizable\": true,\n",366 " \"description\": \"Allison: American English female voice. Dnn technology.\",\n",367 " \"language\": \"en-US\",\n",368 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_AllisonV3Voice\"\n",369 " },\n",370 " {\n",371 " \"gender\": \"female\",\n",372 " \"supported_features\": {\n",373 " \"custom_pronunciation\": true,\n",374 " \"voice_transformation\": false\n",375 " },\n",376 " \"name\": \"es-US_SofiaV3Voice\",\n",377 " \"customizable\": true,\n",378 " \"description\": \"Sofia: North American Spanish (espa\\u00f1ol norteamericano) female voice. Dnn technology.\",\n",379 " \"language\": \"es-US\",\n",380 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/es-US_SofiaV3Voice\"\n",381 " },\n",382 " {\n",383 " \"gender\": \"male\",\n",384 " \"supported_features\": {\n",385 " \"custom_pronunciation\": true,\n",386 " \"voice_transformation\": false\n",387 " },\n",388 " \"name\": \"es-ES_EnriqueV3Voice\",\n",389 " \"customizable\": true,\n",390 " \"description\": \"Enrique: Castilian Spanish (espa\\u00f1ol castellano) male voice. Dnn technology.\",\n",391 " \"language\": \"es-ES\",\n",392 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/es-ES_EnriqueV3Voice\"\n",393 " },\n",394 " {\n",395 " \"gender\": \"male\",\n",396 " \"supported_features\": {\n",397 " \"custom_pronunciation\": true,\n",398 " \"voice_transformation\": false\n",399 " },\n",400 " \"name\": \"de-DE_DieterV3Voice\",\n",401 " \"customizable\": true,\n",402 " \"description\": \"Dieter: Standard German (Standarddeutsch) male voice. Dnn technology.\",\n",403 " \"language\": \"de-DE\",\n",404 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/de-DE_DieterV3Voice\"\n",405 " },\n",406 " {\n",407 " \"gender\": \"female\",\n",408 " \"supported_features\": {\n",409 " \"custom_pronunciation\": true,\n",410 " \"voice_transformation\": false\n",411 " },\n",412 " \"name\": \"it-IT_FrancescaV3Voice\",\n",413 " \"customizable\": true,\n",414 " \"description\": \"Francesca: Italian (italiano) female voice. Dnn technology.\",\n",415 " \"language\": \"it-IT\",\n",416 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/it-IT_FrancescaV3Voice\"\n",417 " },\n",418 " {\n",419 " \"gender\": \"female\",\n",420 " \"supported_features\": {\n",421 " \"custom_pronunciation\": true,\n",422 " \"voice_transformation\": false\n",423 " },\n",424 " \"name\": \"pt-BR_IsabelaVoice\",\n",425 " \"customizable\": true,\n",426 " \"description\": \"Isabela: Brazilian Portuguese (portugu\\u00eas brasileiro) female voice.\",\n",427 " \"language\": \"pt-BR\",\n",428 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/pt-BR_IsabelaVoice\"\n",429 " },\n",430 " {\n",431 " \"gender\": \"male\",\n",432 " \"supported_features\": {\n",433 " \"custom_pronunciation\": true,\n",434 " \"voice_transformation\": false\n",435 " },\n",436 " \"name\": \"en-US_MichaelV3Voice\",\n",437 " \"customizable\": true,\n",438 " \"description\": \"Michael: American English male voice. Dnn technology.\",\n",439 " \"language\": \"en-US\",\n",440 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_MichaelV3Voice\"\n",441 " },\n",442 " {\n",443 " \"gender\": \"female\",\n",444 " \"supported_features\": {\n",445 " \"custom_pronunciation\": true,\n",446 " \"voice_transformation\": false\n",447 " },\n",448 " \"name\": \"es-LA_SofiaV3Voice\",\n",449 " \"customizable\": true,\n",450 " \"description\": \"Sofia: Latin American Spanish (espa\\u00f1ol latinoamericano) female voice. Dnn technology.\",\n",451 " \"language\": \"es-LA\",\n",452 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/es-LA_SofiaV3Voice\"\n",453 " },\n",454 " {\n",455 " \"gender\": \"male\",\n",456 " \"supported_features\": {\n",457 " \"custom_pronunciation\": true,\n",458 " \"voice_transformation\": false\n",459 " },\n",460 " \"name\": \"fr-FR_NicolasV3Voice\",\n",461 " \"customizable\": true,\n",462 " \"description\": \"Nicolas: French (fran\\u00e7ais) male voice. Dnn technology.\",\n",463 " \"language\": \"fr-FR\",\n",464 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/fr-FR_NicolasV3Voice\"\n",465 " },\n",466 " {\n",467 " \"gender\": \"female\",\n",468 " \"supported_features\": {\n",469 " \"custom_pronunciation\": true,\n",470 " \"voice_transformation\": false\n",471 " },\n",472 " \"name\": \"en-GB_KateV3Voice\",\n",473 " \"customizable\": true,\n",474 " \"description\": \"Kate: British English female voice. Dnn technology.\",\n",475 " \"language\": \"en-GB\",\n",476 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-GB_KateV3Voice\"\n",477 " },\n",478 " {\n",479 " \"gender\": \"female\",\n",480 " \"supported_features\": {\n",481 " \"custom_pronunciation\": true,\n",482 " \"voice_transformation\": false\n",483 " },\n",484 " \"name\": \"en-US_OliviaV3Voice\",\n",485 " \"customizable\": true,\n",486 " \"description\": \"Olivia: American English female voice. Dnn technology.\",\n",487 " \"language\": \"en-US\",\n",488 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_OliviaV3Voice\"\n",489 " },\n",490 " {\n",491 " \"gender\": \"female\",\n",492 " \"supported_features\": {\n",493 " \"custom_pronunciation\": true,\n",494 " \"voice_transformation\": false\n",495 " },\n",496 " \"name\": \"es-ES_LauraV3Voice\",\n",497 " \"customizable\": true,\n",498 " \"description\": \"Laura: Castilian Spanish (espa\\u00f1ol castellano) female voice. Dnn technology.\",\n",499 " \"language\": \"es-ES\",\n",500 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/es-ES_LauraV3Voice\"\n",501 " },\n",502 " {\n",503 " \"gender\": \"male\",\n",504 " \"supported_features\": {\n",505 " \"custom_pronunciation\": true,\n",506 " \"voice_transformation\": false\n",507 " },\n",508 " \"name\": \"en-GB_JamesV3Voice\",\n",509 " \"customizable\": true,\n",510 " \"description\": \"James: British English male voice. Dnn technology.\",\n",511 " \"language\": \"en-GB\",\n",512 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-GB_JamesV3Voice\"\n",513 " },\n",514 " {\n",515 " \"gender\": \"male\",\n",516 " \"supported_features\": {\n",517 " \"custom_pronunciation\": true,\n",518 " \"voice_transformation\": false\n",519 " },\n",520 " \"name\": \"en-US_MichaelV2Voice\",\n",521 " \"customizable\": true,\n",522 " \"description\": \"Michael: American English male voice. Dnn technology.\",\n",523 " \"language\": \"en-US\",\n",524 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_MichaelV2Voice\"\n",525 " },\n",526 " {\n",527 " \"gender\": \"female\",\n",528 " \"supported_features\": {\n",529 " \"custom_pronunciation\": true,\n",530 " \"voice_transformation\": false\n",531 " },\n",532 " \"name\": \"en-GB_CharlotteV3Voice\",\n",533 " \"customizable\": true,\n",534 " \"description\": \"Charlotte: British English female voice. Dnn technology.\",\n",535 " \"language\": \"en-GB\",\n",536 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-GB_CharlotteV3Voice\"\n",537 " },\n",538 " {\n",539 " \"gender\": \"female\",\n",540 " \"supported_features\": {\n",541 " \"custom_pronunciation\": true,\n",542 " \"voice_transformation\": false\n",543 " },\n",544 " \"name\": \"en-GB_KateVoice\",\n",545 " \"customizable\": true,\n",546 " \"description\": \"Kate: British English female voice.\",\n",547 " \"language\": \"en-GB\",\n",548 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-GB_KateVoice\"\n",549 " },\n",550 " {\n",551 " \"gender\": \"female\",\n",552 " \"supported_features\": {\n",553 " \"custom_pronunciation\": true,\n",554 " \"voice_transformation\": true\n",555 " },\n",556 " \"name\": \"en-US_AllisonVoice\",\n",557 " \"customizable\": true,\n",558 " \"description\": \"Allison: American English female voice.\",\n",559 " \"language\": \"en-US\",\n",560 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_AllisonVoice\"\n",561 " },\n",562 " {\n",563 " \"gender\": \"male\",\n",564 " \"supported_features\": {\n",565 " \"custom_pronunciation\": true,\n",566 " \"voice_transformation\": false\n",567 " },\n",568 " \"name\": \"es-ES_EnriqueVoice\",\n",569 " \"customizable\": true,\n",570 " \"description\": \"Enrique: Castilian Spanish (espa\\u00f1ol castellano) male voice.\",\n",571 " \"language\": \"es-ES\",\n",572 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/es-ES_EnriqueVoice\"\n",573 " },\n",574 " {\n",575 " \"gender\": \"female\",\n",576 " \"supported_features\": {\n",577 " \"custom_pronunciation\": true,\n",578 " \"voice_transformation\": false\n",579 " },\n",580 " \"name\": \"de-DE_BirgitVoice\",\n",581 " \"customizable\": true,\n",582 " \"description\": \"Birgit: Standard German (Standarddeutsch) female voice.\",\n",583 " \"language\": \"de-DE\",\n",584 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/de-DE_BirgitVoice\"\n",585 " },\n",586 " {\n",587 " \"gender\": \"female\",\n",588 " \"supported_features\": {\n",589 " \"custom_pronunciation\": true,\n",590 " \"voice_transformation\": false\n",591 " },\n",592 " \"name\": \"fr-FR_ReneeVoice\",\n",593 " \"customizable\": true,\n",594 " \"description\": \"Renee: French (fran\\u00e7ais) female voice.\",\n",595 " \"language\": \"fr-FR\",\n",596 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/fr-FR_ReneeVoice\"\n",597 " },\n",598 " {\n",599 " \"gender\": \"male\",\n",600 " \"supported_features\": {\n",601 " \"custom_pronunciation\": true,\n",602 " \"voice_transformation\": true\n",603 " },\n",604 " \"name\": \"en-US_MichaelVoice\",\n",605 " \"customizable\": true,\n",606 " \"description\": \"Michael: American English male voice.\",\n",607 " \"language\": \"en-US\",\n",608 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_MichaelVoice\"\n",609 " },\n",610 " {\n",611 " \"gender\": \"female\",\n",612 " \"supported_features\": {\n",613 " \"custom_pronunciation\": true,\n",614 " \"voice_transformation\": true\n",615 " },\n",616 " \"name\": \"en-US_LisaVoice\",\n",617 " \"customizable\": true,\n",618 " \"description\": \"Lisa: American English female voice.\",\n",619 " \"language\": \"en-US\",\n",620 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/en-US_LisaVoice\"\n",621 " },\n",622 " {\n",623 " \"gender\": \"female\",\n",624 " \"supported_features\": {\n",625 " \"custom_pronunciation\": true,\n",626 " \"voice_transformation\": false\n",627 " },\n",628 " \"name\": \"es-ES_LauraVoice\",\n",629 " \"customizable\": true,\n",630 " \"description\": \"Laura: Castilian Spanish (espa\\u00f1ol castellano) female voice.\",\n",631 " \"language\": \"es-ES\",\n",632 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/es-ES_LauraVoice\"\n",633 " },\n",634 " {\n",635 " \"gender\": \"female\",\n",636 " \"supported_features\": {\n",637 " \"custom_pronunciation\": true,\n",638 " \"voice_transformation\": false\n",639 " },\n",640 " \"name\": \"es-US_SofiaVoice\",\n",641 " \"customizable\": true,\n",642 " \"description\": \"Sofia: North American Spanish (espa\\u00f1ol norteamericano) female voice.\",\n",643 " \"language\": \"es-US\",\n",644 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/es-US_SofiaVoice\"\n",645 " },\n",646 " {\n",647 " \"gender\": \"male\",\n",648 " \"supported_features\": {\n",649 " \"custom_pronunciation\": true,\n",650 " \"voice_transformation\": false\n",651 " },\n",652 " \"name\": \"de-DE_DieterVoice\",\n",653 " \"customizable\": true,\n",654 " \"description\": \"Dieter: Standard German (Standarddeutsch) male voice.\",\n",655 " \"language\": \"de-DE\",\n",656 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/de-DE_DieterVoice\"\n",657 " },\n",658 " {\n",659 " \"gender\": \"female\",\n",660 " \"supported_features\": {\n",661 " \"custom_pronunciation\": true,\n",662 " \"voice_transformation\": false\n",663 " },\n",664 " \"name\": \"it-IT_FrancescaVoice\",\n",665 " \"customizable\": true,\n",666 " \"description\": \"Francesca: Italian (italiano) female voice.\",\n",667 " \"language\": \"it-IT\",\n",668 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/it-IT_FrancescaVoice\"\n",669 " },\n",670 " {\n",671 " \"gender\": \"female\",\n",672 " \"supported_features\": {\n",673 " \"custom_pronunciation\": true,\n",674 " \"voice_transformation\": false\n",675 " },\n",676 " \"name\": \"ja-JP_EmiVoice\",\n",677 " \"customizable\": true,\n",678 " \"description\": \"Emi: Japanese (\\u65e5\\u672c\\u8a9e) female voice.\",\n",679 " \"language\": \"ja-JP\",\n",680 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/ja-JP_EmiVoice\"\n",681 " },\n",682 " {\n",683 " \"gender\": \"male\",\n",684 " \"supported_features\": {\n",685 " \"custom_pronunciation\": false,\n",686 " \"voice_transformation\": false\n",687 " },\n",688 " \"customizable\": false,\n",689 " \"name\": \"ar-AR_OmarVoice\",\n",690 " \"description\": \"Omar: Arabic male voice.\",\n",691 " \"language\": \"ar-AR\",\n",692 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/ar-AR_OmarVoice\"\n",693 " },\n",694 " {\n",695 " \"gender\": \"female\",\n",696 " \"supported_features\": {\n",697 " \"custom_pronunciation\": true,\n",698 " \"voice_transformation\": false\n",699 " },\n",700 " \"customizable\": true,\n",701 " \"name\": \"ko-KR_YoungmiVoice\",\n",702 " \"description\": \"Youngmi: Korean female voice.\",\n",703 " \"language\": \"ko-KR\",\n",704 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/ko-KR_YoungmiVoice\"\n",705 " },\n",706 " {\n",707 " \"gender\": \"female\",\n",708 " \"supported_features\": {\n",709 " \"custom_pronunciation\": true,\n",710 " \"voice_transformation\": false\n",711 " },\n",712 " \"customizable\": true,\n",713 " \"name\": \"ko-KR_YunaVoice\",\n",714 " \"description\": \"Yuna: Korean female voice.\",\n",715 " \"language\": \"ko-KR\",\n",716 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/ko-KR_YunaVoice\"\n",717 " },\n",718 " {\n",719 " \"gender\": \"female\",\n",720 " \"supported_features\": {\n",721 " \"custom_pronunciation\": true,\n",722 " \"voice_transformation\": false\n",723 " },\n",724 " \"customizable\": true,\n",725 " \"name\": \"nl-NL_EmmaVoice\",\n",726 " \"description\": \"Emma: Dutch female voice.\",\n",727 " \"language\": \"nl-NL\",\n",728 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/nl-NL_EmmaVoice\"\n",729 " },\n",730 " {\n",731 " \"gender\": \"male\",\n",732 " \"supported_features\": {\n",733 " \"custom_pronunciation\": true,\n",734 " \"voice_transformation\": false\n",735 " },\n",736 " \"customizable\": true,\n",737 " \"name\": \"nl-NL_LiamVoice\",\n",738 " \"description\": \"Liam: Dutch male voice.\",\n",739 " \"language\": \"nl-NL\",\n",740 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/nl-NL_LiamVoice\"\n",741 " },\n",742 " {\n",743 " \"gender\": \"female\",\n",744 " \"supported_features\": {\n",745 " \"custom_pronunciation\": true,\n",746 " \"voice_transformation\": false\n",747 " },\n",748 " \"customizable\": true,\n",749 " \"name\": \"zh-CN_LiNaVoice\",\n",750 " \"description\": \"Li Na: Chinese (Mandarin) female voice.\",\n",751 " \"language\": \"zh-CN\",\n",752 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/zh-CN_LiNaVoice\"\n",753 " },\n",754 " {\n",755 " \"gender\": \"male\",\n",756 " \"supported_features\": {\n",757 " \"custom_pronunciation\": true,\n",758 " \"voice_transformation\": false\n",759 " },\n",760 " \"customizable\": true,\n",761 " \"name\": \"zh-CN_WangWeiVoice\",\n",762 " \"description\": \"Wang Wei: Chinese (Mandarin) male voice.\",\n",763 " \"language\": \"zh-CN\",\n",764 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/zh-CN_WangWeiVoice\"\n",765 " },\n",766 " {\n",767 " \"gender\": \"female\",\n",768 " \"supported_features\": {\n",769 " \"custom_pronunciation\": true,\n",770 " \"voice_transformation\": false\n",771 " },\n",772 " \"customizable\": true,\n",773 " \"name\": \"zh-CN_ZhangJingVoice\",\n",774 " \"description\": \"Zhang Jing: Chinese (Mandarin) female voice.\",\n",775 " \"language\": \"zh-CN\",\n",776 " \"url\": \"https://api.au-syd.text-to-speech.watson.cloud.ibm.com/instances/35240cd7-e4cb-4350-b640-ab650ad26480/v1/voices/zh-CN_ZhangJingVoice\"\n",777 " }\n",778 " ]\n",779 "}\n"780 ]781 }782 ],783 "source": [784 "import json\n",785 "voices = tts.list_voices().get_result()\n",786 "print(json.dumps(voices, indent=2))"787 ]788 },789 {790 "cell_type": "code",791 "execution_count": 20,792 "metadata": {},793 "outputs": [],794 "source": [795 "# Frere Jacque\n",796 "frere = \"\"\"Frère Jacques\n",797 " Frère Jacques\n",798 " Dormez-vous?\n",799 " Dormez-vous?\n",800 " Sonnez les matines\n",801 " Sonnez les matines\n",802 " Ding, ding, dong\n",803 " Ding, ding, dong\n",804 " Frère Jacques\n",805 " Frère Jacques\n",806 " Dormez-vous?\n",807 " Dormez-vous?\n",808 " Sonnez les matines\n",809 " Sonnez les matines\n",810 " Ding, ding, dong\n",811 " Ding, ding, dong\n",812 " Ding, ding, dong\n",813 " Ding, ding, dong\"\"\""814 ]815 },816 {817 "cell_type": "code",818 "execution_count": 21,819 "metadata": {},820 "outputs": [],821 "source": [822 "with open('./frere.mp3', 'wb') as audio_file:\n",823 " res = tts.synthesize(frere, accept='audio/mp3', voice='fr-FR_ReneeV3Voice').get_result()\n",824 " audio_file.write(res.content)"825 ]826 },827 {828 "cell_type": "code",829 "execution_count": null,830 "metadata": {},831 "outputs": [],832 "source": []833 },834 {835 "cell_type": "code",836 "execution_count": null,837 "metadata": {},838 "outputs": [],839 "source": []840 }841 ],842 "metadata": {843 "kernelspec": {844 "display_name": "Python 3",845 "language": "python",846 "name": "python3"847 },848 "language_info": {849 "codemirror_mode": {850 "name": "ipython",851 "version": 3852 },853 "file_extension": ".py",854 "mimetype": "text/x-python",855 "name": "python",856 "nbconvert_exporter": "python",857 "pygments_lexer": "ipython3",858 "version": "3.7.4"859 }860 },861 "nbformat": 4,862 "nbformat_minor": 2...

Full Screen

Full Screen

vacuum.py

Source:vacuum.py Github

copy

Full Screen

...131 def device_state_attributes(self):132 """Return device state attributes."""133 return {ATTR_CLEANED_AREA: round(self._cleaned_area, 2)}134 @property135 def supported_features(self):136 """Flag supported features."""137 return self._supported_features138 def turn_on(self, **kwargs):139 """Turn the vacuum on."""140 if self.supported_features & SUPPORT_TURN_ON == 0:141 return142 self._state = True143 self._cleaned_area += 5.32144 self._battery_level -= 2145 self._status = "Cleaning"146 self.schedule_update_op_state()147 def turn_off(self, **kwargs):148 """Turn the vacuum off."""149 if self.supported_features & SUPPORT_TURN_OFF == 0:150 return151 self._state = False152 self._status = "Charging"153 self.schedule_update_op_state()154 def stop(self, **kwargs):155 """Stop the vacuum."""156 if self.supported_features & SUPPORT_STOP == 0:157 return158 self._state = False159 self._status = "Stopping the current task"160 self.schedule_update_op_state()161 def clean_spot(self, **kwargs):162 """Perform a spot clean-up."""163 if self.supported_features & SUPPORT_CLEAN_SPOT == 0:164 return165 self._state = True166 self._cleaned_area += 1.32167 self._battery_level -= 1168 self._status = "Cleaning spot"169 self.schedule_update_op_state()170 def locate(self, **kwargs):171 """Locate the vacuum (usually by playing a song)."""172 if self.supported_features & SUPPORT_LOCATE == 0:173 return174 self._status = "Hi, I'm over here!"175 self.schedule_update_op_state()176 def start_pause(self, **kwargs):177 """Start, pause or resume the cleaning task."""178 if self.supported_features & SUPPORT_PAUSE == 0:179 return180 self._state = not self._state181 if self._state:182 self._status = "Resuming the current task"183 self._cleaned_area += 1.32184 self._battery_level -= 1185 else:186 self._status = "Pausing the current task"187 self.schedule_update_op_state()188 def set_fan_speed(self, fan_speed, **kwargs):189 """Set the vacuum's fan speed."""190 if self.supported_features & SUPPORT_FAN_SPEED == 0:191 return192 if fan_speed in self.fan_speed_list:193 self._fan_speed = fan_speed194 self.schedule_update_op_state()195 def return_to_base(self, **kwargs):196 """Tell the vacuum to return to its dock."""197 if self.supported_features & SUPPORT_RETURN_HOME == 0:198 return199 self._state = False200 self._status = "Returning home..."201 self._battery_level += 5202 self.schedule_update_op_state()203 def send_command(self, command, params=None, **kwargs):204 """Send a command to the vacuum."""205 if self.supported_features & SUPPORT_SEND_COMMAND == 0:206 return207 self._status = f"Executing {command}({params})"208 self._state = True209 self.schedule_update_op_state()210class StateDemoVacuum(StateVacuumDevice):211 """Representation of a demo vacuum supporting states."""212 def __init__(self, name):213 """Initialize the vacuum."""214 self._name = name215 self._supported_features = SUPPORT_STATE_SERVICES216 self._state = STATE_DOCKED217 self._fan_speed = FAN_SPEEDS[1]218 self._cleaned_area = 0219 self._battery_level = 100220 @property221 def name(self):222 """Return the name of the vacuum."""223 return self._name224 @property225 def should_poll(self):226 """No polling needed for a demo vacuum."""227 return False228 @property229 def supported_features(self):230 """Flag supported features."""231 return self._supported_features232 @property233 def state(self):234 """Return the current state of the vacuum."""235 return self._state236 @property237 def battery_level(self):238 """Return the current battery level of the vacuum."""239 if self.supported_features & SUPPORT_BATTERY == 0:240 return241 return max(0, min(100, self._battery_level))242 @property243 def fan_speed(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful