Skip to main content

an openai based game audio translator

Project description

openai-game-translator

ChatGPT API based video game audio translator application and web service

License GitHub issues build codecov PyPI Documentation Status Doc

Overview

A game translation app that uses the ChatGPT API to recognize in-game speech (TODO: and even game visuals) and provide smooth text translations on platforms like Switch and PS5, thanks to the powerful language abilities of GPT.

Prerequisites

If you don't already have local credentials setup for your AWS account, you can follow this guide for configuring them using the AWS CLI.

  • Since we use amazon-transcribe SDK, which is built on top of the AWS Common Runtime (CRT), non-standard operating systems may need to compile these libraries themselves.
  • Should at least set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables and in [default] profile ~/.aws/credentials.

Also, ensure that you have portaudio, which is a prerequisite for pyAudio

sudo apt install portaudio19-dev # linux
brew install portaudio # macos

Installation

Install the latest version from pip

pip install openai-game-translator

Install from github repository

git clone https://github.com/Erisae/openai-game-translator
cd openai-game-translator
make install

Quick Start

Terminal Usage

To translate audio to text in the terminal, use the command translate. The simplest way to achieve this is through AWS's real-time media transcription and GPT-based translation, as shown below:

translate --openai_key <openai_key> -i <input_language> -o <output_language> aws_live
  • <openai_key>: A valid OpenAI API key is required for inferencing GPT model to translate.
  • <input_language>: Language of the audio to be transcribed.
  • <output_language>: Target language for the translation.
  • aws_live: This option uses the AWS live stream transcription model, allowing the voice data stream to be uploaded to AWS services using the AWS SDK while recording the voice. Other available audio transcription models include aws_pre and xunfei, but they require additional arguments such as --file, --pre_recorded, and audio transcription API tokens from xunfei.
  • Note that aws_live, aws_pre, xunfei work as subcommands. Ensure that openai_key, input_language and output_language are assigned before running these subcommands, as otherwise the argument values might not be recognized correctly. For more information about how to use the package in command line, refer to the documentation.

Script Usage

In script, simply pass aws_live to initialize a gameTranslator, translator.openai_translation() will translate Chinese audio to English text.

import openai
from game_translator import gameTranslator

openai.api_key = "<openai_key>"
translator = gameTranslator("aws_live", input_language="chinese", output_language="english")
translator.openai_translation()

Examples

Shell xunfei prerecorded example

translate --openai_key <openai_key>  -o english -i chinese xunfei --xunfei_appid <xunfei_appid> --xunfei_apikey  <xunfei_apikey> --xunfei_apisecret <xunfei_apisecret> --file audio_sample_little.wav --pre_recorded
****************************************
Transcription model : xunfei
Using prerecorded audio file : audio_sample_little.wav
Input  language : chinese
Output language : english
****************************************
transcription success...
科大讯飞是中国最大的智能语音技术提供商。
translation success...
iFlytek is the largest intelligent voice technology provider in China.
Elapsed time: 3.813 seconds

Script AWS live example

translator = gameTranslator("aws_live")
translator.openai_translation()
****************************************
Transcription model : aws_live
Using prerecorded audio file : None
Input  language : chinese
Output language : english
****************************************
start detecting audio...
current rms: ##                  |
detecting finished...
transcription success...
明天的期末考试我能考多少
translation success...
How much can I score on tomorrow's final exam?
Elapsed time: 9.155 seconds

Contributing

See more at CONTRIBUTING.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai-game-translator-1.3.0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

openai_game_translator-1.3.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file openai-game-translator-1.3.0.tar.gz.

File metadata

File hashes

Hashes for openai-game-translator-1.3.0.tar.gz
Algorithm Hash digest
SHA256 e97b12ac78e639aae50f42038de91d0742c361212932afed11d2748bc3e13751
MD5 25cc21af093cc83643980e2b90668ed5
BLAKE2b-256 5725cde25e19ef4d37e906f8a714aad9af8384ae90a3f26b68875fcfdabdfb4c

See more details on using hashes here.

File details

Details for the file openai_game_translator-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_game_translator-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1dfad862af3c7fbf9899b85dcc5c98043aef5dd1ad5950d6da6f210fbb07ad6
MD5 9c923a57f11d8ad7e723560f31588ec4
BLAKE2b-256 fa259c72e122aeb28b6ac46cfa15d985eb43e5955e6bbda35388ff59cdd52f7d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page