<jupyter_start><jupyter_text>This code demonstrates the capability for doing the following:1. Text to Text Language translation by converting from English to Hindi2. Text to audio Language translation by converting from English to German<jupyter_code>!pip install ibm_watson
!pip install ibm_cloud_sdk_core
#credentials for Language Translation 

apiKey = "<KEY>"
url = "https://api.eu-gb.language-translator.watson.cloud.ibm.com/instances/033994a0-07cc-4051-99db-1df755ff86fb"
#Importing Dependencies
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_watson import LanguageTranslatorV3
#setting up the services

authenticator = IAMAuthenticator(apiKey)
lt = LanguageTranslatorV3(version='2018-05-01', authenticator=authenticator)
lt.set_service_url(url)
#translating from English to Hindi 

translation = lt.translate(text='The leaf condition is good', model_id='en-hi').get_result()

#Eng to German ex: 
#translation = lt.translate(text='Welcome.', model_id='en-de').get_result()
print (translation)
#Extracting the needed info:

translation['translations'][0]['translation']
#Identifying the language:

languageID = lt.identify(translation).get_result()
languageID<jupyter_output><empty_output><jupyter_text>Perfoming Language Translation and Text to Speech<jupyter_code>#Credentials for Text to Speech

ttsapikey  = "<KEY>"
ttsurl  = "https://api.eu-gb.text-to-speech.watson.cloud.ibm.com/instances/ae3533a6-4455-47fc-9e5f-e12952472aab"
from ibm_watson import TextToSpeechV1
# Authenticate
ttsauthenticator = IAMAuthenticator(ttsapikey)
tts = TextToSpeechV1(authenticator=ttsauthenticator)
tts.set_service_url(ttsurl)
#English to German [as audio translation to Hindi is "unavailable" within IBM we are trying with another language ]

translation = lt.translate(text='The leaf got a viral infection. Please take action', model_id='en-de').get_result()
translation

text = translation['translations'][0]['translation']
text
with open('./recommendation.mp3', 'wb') as audio_file:
    res = tts.synthesize(text, accept='audio/mp3', voice='de-DE_BirgitV3Voice').get_result()
    #res = tts.synthesize(text, accept='audio/mp3').get_result()
    audio_file.write(res.content)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10831460674157303, 'fraction_numerical': 0.027865168539325844, 'mean_word_length': 7.124087591240876, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '661453', 'license': 'Apache-2.0', 'n_tokens_mistral': 785, 'n_tokens_neox': 716, 'n_words': 166, 'path': 'DHAAN_LT_Model.ipynb', 'repo_name': 'zero-hunger-cfc-2k21/DHAAN-Language-Translator', 'size': '2303'}