# 翻譯蒟蒻 ## Week 1C ---- ## 簡介 最近 Meta 釋出 SeamlessM4T 支援 100 種語言,語音與文字互相翻譯 包含文字翻譯、語音辨識、語音合成等 [Blog](https://ai.meta.com/blog/seamless-m4t/) | [GitHub](https://github.com/facebookresearch/seamless_communication) | [Paper](https://dl.fbaipublicfiles.com/seamless/seamless_m4t_paper.pdf) Demo [Official](https://seamless.metademolab.com/) | [HF Space](https://huggingface.co/spaces/facebook/seamless_m4t) | [Colab](https://colab.research.google.com/drive/1r4IQAiVAtEz-4yIvqoEcA1lFZLbXFPTV?hl=en) | [Colab Gradio](https://colab.research.google.com/drive/110d7rjVyAQX7Gg9ixtRD3pk0nP-tM0Iy?hl=en) ---- ## 架構 ![](https://i.imgur.com/HiriCMF.png) ---- ## 環境 ```bash= git clone https://github.com/facebookresearch/seamless_communication.git cd seamless_communication pip install . conda install -y -c conda-forge libsndfile ``` ---- ## 初始化 ```python= import torch from seamless_communication.models.inference import Translator model = "seamlessM4T_large" # or "seamlessM4T_medium" translator = Translator( model, vocoder_name_or_card="vocoder_36langs", device=torch.device("cuda:0"), dtype=torch.float16, ) ``` 模型大小約 10 GB,在 Colab 上只要花一分鐘下載 ---- ## 翻譯文字 ```python= results = translator.predict( input="今天天氣真好!", task_str="T2ST", src_lang="eng", tgt_lang="cmn", spkr=-1, ) translated_text, wav, sr = results ``` `spkr` 可以選不同 TTS 語者 `sr` 為輸出音檔用的 Sample Rate 可用的語言可以參考[這份檔案](https://github.com/facebookresearch/seamless_communication/blob/main/src/seamless_communication/assets/cards/vocoder_36langs.yaml) ---- ## 輸出音檔 透過 `torchaudio` 輸出 `.wav` 音檔 ```python= import torchaudio torchaudio.save("output.wav", wav.squeeze(0).cpu(), sr) ``` 在 Jupyter 上直接顯示播放元件 ```python= from IPython.display import Audio Audio(wav.squeeze(0).cpu(), rate=sr) ``` ---- ## 翻譯音檔 ```python= results = translator.predict( input="output.wav", task_str="S2ST", tgt_lang="cmn", ) translated_text, wav, sr = results ``` --- # 其他分享 ---- ## 秒殺容器 有些容器在停止時會花很久的時間 是因為 `docker stop` 會先送出 `SIGTERM` 十秒後才送出 `SYSKILL` 的訊號 可以直接 `docker stop -t 1` 秒殺 [ChatGPT Reference](https://chat.openai.com/share/15f53a67-39eb-41da-8d94-0a2ed533464b) ---- ## LLM & Image 最近 Bard 與 Bing Chat 都支援上傳圖片了 [Bard with Image](https://bard.google.com/?hl=en) ---- ## Python 不朽 Python 預計加入 Immortal Objects 提升記憶體效率 (Share Memory) 解除平行運算限制 [News Link](https://www.ithome.com.tw/news/158384) ---- ## 遙遙領先的 IDE 來自中國、領先世界的 CEC-IDE [GitHub Issue](https://github.com/microsoft/vscode/issues/191229) ---- ## Shell Script Trap Trap 機制可以捕捉類似 Ctrl + C 的訊號 讓 Shell Script 可以做一些例外處理或垃圾回收 ```bash= cleanup() { rm -f /tmp/tempfile } trap cleanup EXIT touch /tmp/tempfile ``` ChatGPT Reference - [Link 1](https://chat.openai.com/share/4a6ec6e8-65b2-4249-85ff-3bf8911b17d6) | [Link 2](https://chat.openai.com/share/61aa4120-d7be-4cb2-ad9e-6cf8ac13e21d) ---- ## TTS [TTS Maker](https://ttsmaker.com/zh-hk) [雅婷文字轉語音](https://tts.yating.tw/#exp) [雅婷逐字稿](https://asr.yating.tw/) ---- ## OpenCC Converter [自製簡繁轉換器](https://penut85420-opencc-converter.hf.space/) [OpenCC GitHub](https://github.com/BYVoid/OpenCC)
{"slideOptions":"{\"transition\":\"slide\"}","description":"地獄貓旅行團第 28 週心得分享","lang":"zh-TW","title":"Week 1C - 翻譯蒟蒻","contributors":"[{\"id\":\"c7cbb212-2c41-4dfa-8d85-f8e7fa769bf1\",\"add\":3723,\"del\":592}]"}
    219 views
   Owned this note