Posts

Showing posts from October, 2022

Natural Language Processing Libraries (in Python)

Image
Picture from Pixabay (https://www.pexels.com/@pixabay/) I was trying out 3 Natural Language Processing ( NLP ) Python Libraries. Mainly to see if they can extract nouns from sentences; and their execution time. nltk==3.7 spacy==3.4.1 textblob==0.17.1 import nltk nltk.download("punkt") nltk.download("averaged_perceptron_tagger") import spacy from spacy.cli.download import download download(model="en_core_web_sm") spacy_nlp = spacy.load("en_core_web_sm") from textblob import TextBlob import ssl import time try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: pass else: ssl._create_default_https_context = _create_unverified_https_context txt = """The Natural Language Processing group focuses on developing efficient algorithms to process text and to make their information accessible to computer applications.""" def time_taken(func): def wrapper():

Translator powered by Azure Cognitive Services

Image
  Picture from Pavel Danilyuk (https://www.pexels.com/@pavel-danilyuk/) After toying with a few Azure Cognitive Services ( here , here , and here ), this is the final blog around these services. I piece them into a Speech-to-Speech translation application. Using a simple web page, I capture the voice and send it over to the Speech-to-Text service to get the translated message. From this text, the Translation service translates the message from English to a target language. Finally, the Text-to-Speech service generates the voice for the translated message. Here is a demo The source code is at github .

Azure Text-to-Speech Service

Image
  Picture from  Alex Knight  @ https://www.pexels.com/ After blogging about Azure Speech-to-Text Service , here we have the Text-to-Speech blog. The setup is identical to the Speech-to-Text Service blog. and here is the Python code. import azure.cognitiveservices.speech as speech_sdk import os voices = [ "en-GB-ThomasNeural", # English (United Kingdom) "en-SG-WayneNeural", # English (Singapore) "en-US-MonicaNeural", # English (USA) "en-IN-NeerjaNeural", # Engish (India) ] text = "To empower every person and every organization on the planet to achieve more." if __name__ == "__main__": speech_key, service_region = ( os.environ["AZURE_SPEECH_KEY"], os.environ["AZURE_SPEECH_LOC"], ) speech_config = speech_sdk.SpeechConfig( subscription=speech_key, region=service_region) audio_config = speech_sdk.audio.AudioOutputConfig( use_default_speaker=

Azure Speech to Text Service

Image
Picture from ThisIsEngineering   Yet another coding exercise on Azure Cognitive Services . This time, we have Azure Speech to Text Service in Python . I am referencing this code . 1. Initialize Setup First and foremost, I need to do the following Create a resource group Create Azure Cognitive Translation Services in this resource group. Copy the key and location values as shown below (Note endpoint value is not needed). For simplicity, I have two values as environment parameters, AZURE_SPEECH2TEXT_KEY , and AZURE_SPEECH2TEXT_LOC . 2. Code FYI, I am using MacOSX 2.1 Install library pip3 install azure-cognitiveservices-speech==1.23.0 2.2 Code import azure.cognitiveservices.speech as speech_sdk import os if __name__ == "__main__": speech_key, service_region = ( os.environ["AZURE_SPEECH2TEXT_KEY"], os.environ["AZURE_SPEECH2TEXT_LOC"], ) speech_config = speech_sdk.SpeechConfig( subscription=speech_key, region=service_region

Azure Translation Service

Image
  Picture from  Alex Knight @ https://www.pexels.com/ As of today, there are no clients for Azure Translation Service, hence requests have to be made through HTTP calls. I am referencing this tutorial however, I need to make changes to the path of the URL. 1. Initialize Setup First and foremost, I need to do the following Create a resource group Create Azure Cognitive Translation Services in this resource group. Copy the key, endpoint, and location values as shown below. For simplicity, I have values as environment parameters, AZURE_TRANSLATOR_KEY ,  AZURE_TRANSLATOR_ENDPOINT , and AZURE_TRANSLATOR_LOC . 2. Code FYI, I am using MacOSX and Typescript. import axios from "axios"; import { v4 } from "uuid"; import * as process from "process"; const AZURE_TRANSLATOR_KEY = process.env["AZURE_TRANSLATOR_KEY"]; const AZURE_TRANSLATOR_ENDPOINT = process.env["AZURE_TRANSLATOR_ENDPOINT"]; const AZURE_TRANSLATOR_LOC = process.env["AZURE_TRAN

Text Analytics for health

Image
  Picture from Andrea pixabay (https://www.pexels.com/@pixabay/) I was introduced to Text Analytics for Health which is part of Azure Cognitive Service for Language . And, I wanted to see how it works. So I create a small Python Program. 1. Initialize Setup First and foremost, I need to do the following Create a resource group Create an Azure Cognitive Services Text Analytics in this resource group. Copy the key and endpoint values as shown below. For simplicity, I have two values as environment parameters,  AZURE_LANG_KEY and  AZURE_LANG_ENDPOINT . 2. Code FYI, I am using MacOSX. 2.1 Install library pip3 install azure-ai-textanalytics==5.2.0 2.2 Python Code The Python code is very concise and self-explanatory. import json import sys import os from azure.ai.textanalytics import TextAnalyticsClient from azure.core.credentials import AzureKeyCredential def execute(text): # export the key and endpoint in environment parameters, # AZURE_LANG_KEY and AZURE_LANG_ENDPOINT resp