papagopy 0.1.11
papago translator for python3
License: MIT
Requires Python: >=3
Keywords: papago,translator,naver,translate

# papagopy

### Unofficial papago python wrapper

## TODO:
- [ ] cli 만들기


## Compliance from [Papago](https://papago.naver.com/)

```
1. Precautions related to subject of translation
The translation content should only include the related rights for the content that the user directly holds(copyright, etc.), and please do not include the others' works or personal information. For example, entering the contents of the famous works by the existing author as it is or entering the ID content may infringe the third party rights, so please exclude them from translation requests.

2. Scope of use of Papago TTS output (voice files)
The rights related to the Papago TTS (Text to Speech) output (voice file) (rights to translation and used voice, etc. - except the rights to the input itself) reserved by NAVER Corporation and the voice actor who provided the voice.

The output is available only for the purpose of listening to the input text/translation result on the Papago, and using it for any other purposes (including non-commercial purposes or uses) in an online service (corporate/private broadcast) or an offline (school/private academy classes) is strictly prohibited.

※ If you want to use the voice synthesis service for non-commercial purposes or uses, please use the CLOVA Dubbing service.

If any violation of the above compliance is found, legal actions may be taken. So please comply with the above.
```

`I do not own anything about Papago Service. Use it at your own risk.`


## Installation and basic usage

`python3 -m pip install papagopy`
```python3
from papagopy import Papagopy
translator = Papagopy()
print(
  translator.translate('hello', targetCode='ko')
)
```


## Requirements

- python 3 or higher

- `requests`



## Features

- supports official api calls and web api calls

- translate a string over 5000 length

- supports tts (for some languages)



## Examples

``` python3
from papagopy import Papagopy

translator = Papagopy(api={"clientId1":"clientSecret1", "clientId2":"clientSecret2"}) # use official apis
translator_web = Papagopy() # use web api

print(translator.detectLang('考え過ぎないでください'))
# returns "ja"

print(translator.translate('考え過ぎないでください', targetCode='ko'))
# returns "너무 생각하지 마세요"

print(translator.tts('考え過ぎないでください'))
# returns "{'0': '// url to audio file //'}"
```

# Documentation

> ## Initialization

## Papagopy(api={}, debug=False, retry=5, requestTimeout=3, sleepMaxMS=4321, proxy={})

api(dict): `{"clientId":"cliendSecret", ...}`. You can get this values from [here](https://developers.naver.com/main)

debug(bool): if `True`, it logs a lot more information on terminal using `print` function.

retry(int): a retry value for web api calls

requestTimeout(int): a requests call timeout value

sleepMaxMS(int): a sleep time between web api calls

proxy(object): proxy options for requests calls. check also [here](https://docs.python-requests.org/en/latest/user/advanced/#proxies)

> ## Methods

## detectLang(source, returnRaw=False)

source(str): a text to be used to detect a language.

returnRaw(bool): if `True`, it returns a JSON object received from papago server. if `False`, it returns only a language code.

## translate(source, targetCode, sourceCode='', method='n2mt', honorific=False, returnRaw=False)

source(str): a text to be translated.

targetCode(str): a language code of translated text. check [here](https://github.com/k123s456h/papagopy/blob/main/papagopy/constants.py#L2).

sourceCode(str): a language code of source. if not set, papagopy will automatically set it using it's internal `detectLang` method.

method(str): a translation method. You can set `n2mt` or `nsmt`, but I recommend to use `n2mt`. `n2mt` means `Naver Neural Machine Translation` and `nsmt` means `Naver Statistical Machine Translation`. Some language does not support `n2mt` method, then it automatically use `nsmt` method.

honorific(bool): use honorific words in translated text, especially in korean language. 

returnRaw(bool): similar as a `returnRaw` argument in `detectLang` method.

## tts(text, sex=True, speed=0, alpha=0, pitch=0, save=False)

### check [here](https://github.com/k123s456h/papagopy/blob/main/papagopy/constants.py#L65) for supported languages.

return(dict): {'idx1': 'audio url1', 'idx2': 'audio url2', ...}

> Due to text length limit, any text over 5000 length will be splitted into several chunks to be processed. That's why `tts` returns dictionary value. However downloaded `mp3` file will be always one file no matter how long the source text.

text(str): a text to be converted to audio file.

sex(bool): if `True`, it will use a male voice. if `False`, it will use a female voice.

speed(int): a integer value -5(slow) to 5(fast). 0 is normal speed.

alpha(int): a integer value -5 to 5.

pitch(int): a integer value -5 to 5.

save(bool): if `True`, it will save `mp3` file to your current working directory. else it returns dict object that contains url to audio file.


---

papago@v1.6.3