Synchronous document (PPT) translation via API not working

Sam_C 0 Reputation points
2024-09-12T13:38:41.1466667+00:00

Hello my friends,

I wanted to translate a large PPT file based on the following instructions:

https://learn.microsoft.com/en-us/azure/ai-services/translator/document-translation/reference/translate-document

  • I set up the Azure account
  • I obtained the API key and the custom domain endpoint
  • I was trying to translated from English (en) to Traditional Chinese (zh-Hant)

Here's the command I used on cmd:

curl -i -X POST "https://translatefortaiwan.cognitiveservices.azure.com//translator/document:translate?sourceLanguage=en&targetLanguage=zh-Hant&api-version=2024-05-01" -H "Ocp-Apim-Subscription-Key:{ API key }" -F "document=C:\Users\xxxx\Desktop\testppt.pptx;type=application/vnd.openxmlformats-officedocument.presentationml.presentation" -o "C:\Users\xxxx\Desktop\testppt_translated.pptx"

Something happened, here's the output message:

% Total % Received % Xferd Average Speed Time Time Time Current

                             Dload  Upload   Total   Spent    Left  Speed

100 350 0 69 100 281 193 786 --:--:-- --:--:-- --:--:-- 985

Afterwards a new ppt (translated version) was generated but there's nothing in it.

Can anyone please shed some lights?

Sam

Azure Translator
Azure Translator
An Azure service to easily conduct machine translation with a simple REST API call.
390 questions
{count} votes

2 answers

Sort by: Most helpful
  1. santoshkc 8,100 Reputation points Microsoft Vendor
    2024-09-13T16:02:16.72+00:00

    Hi @Sam_C,

    Thank you for your patience.

    I tried to reproduce the scenario without any issue and was able to translate the .pptx file. Here is the curl command:

    curl -i -X POST "https://<END-POINT-NAME>.cognitiveservices.azure.com/translator/document:translate?sourceLanguage=en&targetLanguage=zh-Hant&api-version=2024-05-01" -H "Ocp-Apim-Subscription-Key:<KEY>" -F "document=@<FILE_PATH>;type=application/vnd.openxmlformats-officedocument.presentationml.presentation" -o "<OUTPUT_FILE_PATH>"
    

    As I observed from your curl command: Instead of one slash '/' there are two slashes after cognitiveservices.azure.com// and '@' is missing. Please check this from your side. For more info, please refer to the below screenshot of curl command.

    Replace END-POINT-NAME, KEY, FILE_PATH and OUTPUT_FILE_PATH with your actual values.

    Output:

    User's image

    Translated ppt file:

    User's image

    I hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.


  2. Sam_C 0 Reputation points
    2024-09-19T00:22:50.8633333+00:00

    Hi Santoshk,

    At the time when you were writing this I still hadn't given async translation a try (translate files in blob). afterwards I gave it try following the instruction in this link:

    https://learn.microsoft.com/en-us/azure/ai-services/translator/document-translation/how-to-guides/use-rest-api-programmatically?tabs=python

    I did the following:

    • I obtained the SASurl for both source and destination storage of both blob folders.
    • I obtained the key for my azure account
    • I changed the access policies of both source and destination blob storage (read/list for source, and write/list for destination) .

    And used this script to run it :

    import requests
    
    base_path = '{your-document-translation-endpoint}/translator/document/batches'
    
    key =  '{your-api-key}'
    
    route = '?api-version={date}'
    
    constructed_url = base_path + route
    
    payload= {
    
    "inputs": [
    
        {
    
            "source": {
    
                "sourceUrl": "https://YOUR-SOURCE-URL-WITH-READ-LIST-ACCESS-SAS",
    
                "storageSource": "AzureBlob",
    
                "language": "en"
    
            },
    
            "targets": [
    
                {
    
                    "targetUrl": "https://YOUR-TARGET-URL-WITH-WRITE-LIST-ACCESS-SAS",
    
                    "storageSource": "AzureBlob",
    
                    "category": "general",
    
                    "language": "es"
    
                }
    
            ]
    
        }
    
    ]
    }
    
    headers = {
    
      'Ocp-Apim-Subscription-Key': key,
    
      'Content-Type': 'application/json'
    
    }
    response = requests.post(constructed_url, headers=headers, json=payload)
    
    print(f'response status code: {response.status_code}\nresponse status: {response.reason}\nresponse headers: {response.headers}')
    Results: 
    
    
    

    Output on command prompt:

    response status code: 202

    response status: Accepted response headers: {'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json; charset=utf-8', 'X-RequestId': '0c16fb2d-f966-420e-a515-3024255dd354', 'Operation-Location': 'https://translatefortaiwan.cognitiveservices.azure.com/translator/document/batches/7679bc6f-ae13-4b6a-9d41-8c1dd6986b56?api-version=2024-05-01', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'apim-request-id': '0c16fb2d-f966-420e-a515-3024255dd354', 'x-content-type-options': 'nosniff', 'x-ms-region': 'East Asia', 'Date': 'Wed, 18 Sep 2024 07:54:51 GMT'} No file was translated and placed at the target folder. Sam


Your answer

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