Does Azure have an API for separating sentences with new lines from long Docx documents?

i'm MariOhn 101 Reputation points
2023-01-03T03:31:50.18+00:00

I'm going to make subtitles from long text, but splitting long text into multiple sentences is a bit of a waste of time. I think AI will come to my aid in this, I would like to know if there is this service here.

Azure Language in Foundry Tools
Azure Language in Foundry Tools

An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.

Foundry Tools
Foundry Tools

Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform

0 comments No comments

1 answer

Sort by: Most helpful
  1. Ramr-msft 17,836 Reputation points
    2023-01-03T13:02:06.947+00:00

    One approach you could consider is using Azure's Text Analytics API, which provides various natural language processing capabilities, including sentence boundary detection.

    To use the Text Analytics API to split long text into sentences, you would first need to sign up for an Azure account and set up a Text Analytics resource. Then, you can use the API to send the long text to be analyzed, and the API will return the text with sentences separated by new lines. Here is an example of how you could use the Text Analytics API in Python to split long text into sentences:

    import requests  
      
    # Replace YOUR_KEY with your Text Analytics API key  
    api_key = "YOUR_KEY"  
      
    # Set the endpoint URL  
    endpoint = "https://<YOUR_RESOURCE_NAME>.cognitiveservices.azure.com/text/analytics/v3.1-preview.3/languages"  
      
    # Set the headers  
    headers = {  
        "Ocp-Apim-Subscription-Key": api_key  
    }  
      
    # Set the document  
    document = {  
        "documents": [  
            {  
                "id": "1",  
                "text": "This is a long text with multiple sentences. Here is another sentence. And another one. And one more."  
            }  
        ]  
    }  
      
    # Send the request  
    response = requests.post(endpoint, headers=headers, json=document)  
      
    # Get the sentences  
    sentences = response.json()["documents"][0]["sentences"]  
      
    # Print the sentences  
    for sentence in sentences:  
        print(sentence["text"])  
    

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.