You’re right, while Google Translate’s website shows pinyin for Chinese input, it isn’t directly available through their official Translate API. However, you can achieve this by using a combination of libraries and APIs.
Here are some different options you could explore:
Open Chinese Convert: This library helps convert Chinese text between different scripts and can be adapted for pinyin extraction. You can find more information in the OpenCC GitHub repository.
Combining with Google Translate API: To integrate with the Google Translate API, first translate your Chinese text using the API, then utilize a Pinyin library to convert the translated text (now in the target language) back into pinyin. Pinyin libraries analyze Chinese characters and apply specific rules to determine their corresponding pronunciations, allowing you to obtain pinyin for any language supported by Google Translate.
Additional considerations:
You can also check this official guide that explains how to use the API for language translation.
I came across an article/blog that addresses a method to convert Chinese characters to pinyin in Google Sheets, providing a workaround for those without access to a suitable API.
The pypinyin library provides options to include tone marks in the output, while if you need to segment Chinese text into words, you can use libraries like jieba in Python before performing the pinyin conversion.