Show HN:我教会AI实时解说乒乓球
Show HN: I taught AI to commentate Pong in real time

原始链接: https://github.com/pncnmnp/xpong

xPong是一款增强型乒乓球游戏,加入了由大型语言模型生成的解说,这是开发者自2020年就开始构思的项目,直到最近借助OpenAI的gpt-4o-mini-tts才得以实现。游戏模拟了为期16年的乒乓球锦标赛,包含模拟玩家的Elo排名和比赛结果。第16年,排名前两位的选手将争夺世界冠军。 解说是游戏的核心特色,包括开场白、实时逐球描述和赛后总结。两位解说员以对话的方式进行解说,对比赛中的关键事件做出反应。这种动态解说由一个基于事件的管道驱动,该管道记录动作、将其转换为指标、进行优先级排序,并使用TTS将生成的解说转换成语音。 利用15年的模拟历史数据,xPong使用最近邻搜索来查找类似的过往比赛,提供见解,甚至可以幽默地将其与传奇选手进行比较。设置需要一个OpenAI API密钥、一个基于Chromium的浏览器,以及通过`pip3 install -r requirements.txt`安装依赖项。`--cache`和`--no-opening`等选项允许自定义设置。游戏采用MIT许可证授权,并使用公开许可的音效。

Hacker News 最新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Show HN: 我教会 AI 实时解说 Pong 游戏 (github.com/pncnmnp) 8 分,来自 pncnmnp,2 小时前 | 隐藏 | 过去 | 收藏 | 讨论 加入我们 6 月 16-17 日在旧金山举办的 AI 初创公司学校! 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系我们 搜索:

原文

ChatGPT Image Apr 28, 2025, 12_15_40 AM

As the name suggests, xPong is all about Pong — but with a twist: there’s LLM-based commentary generation integrated into the game.

I’ve wanted to do this for the longest time — in fact, back in my undergrad days, I used to carry around a GitHub Gist to store such ideas, and an entry for this one dates back to Feb 16 2020. That’s five years! Anyway, for the longest time we never had the right technology to pull this off in a cost-effective, near-realtime manner.

However, late last month, with OpenAI’s gpt-4o-mini-tts, we finally have the resources to do it! I envision a future where gpt-4o-mini-tts-like software is integrated on the edge. When that happens, next-generation gaming consoles will leverage such technology, opening up a whole universe of possibilities in gaming, especially in sports-simulation titles.

Hope you have a blast tinkering with this game and its source code!

Screenshot 2025-05-01 at 23-22-12 (1722) We taught an AI to commentate Pong in Real Time - YouTube

Before installing the dependencies, I encourage you to create and activate a virtual environment - for example, run python3 -m venv .venv and then source .venv/bin/activate on macos/linux.

To install the Python dependencies, use:

pip3 install -r requirements.txt

Next, create an API key in OpenAI’s dashboard. For this, follow the steps in OpenAI’s Create and export an API key docs. Once you have the key, store it in a .env file at the root of this repository:

OPENAI_API_KEY=your-api-key

Because this code leverages an Electron-like library Eel, you will also need a Chromium-based browser.

When everything is set up, run:

Add --cache to cache LLM-generated player metadata for later runs, and --no-opening to skip the opening commentary.

It’s packed with ideas!

  • There’s a tournament simulator that simulates 15 years' worth of tournaments. Each year includes four majors — sixty events in all. Players and matches are simulated using Elo.
  • In the 16th year, when the main match starts, the world’s top two players face off in the World Championship Final.
  • Two AIs are playing against each other in a game of Pong, with variations in their reaction times and shot speeds.
  • The commentary logic has three layers - opening commentary with a scorecard, in-game ball-by-ball commentary, and closing commentary.
  • Two commentators take turns talking to each other and the audience.
  • Commentary is interrupted when an important in-game event occurs, then resumes from where it left off afterward.
  • In-game commentary is driven by an event-based pipeline: actions are logged as events, periodically parsed into metrics, those metrics are ranked by priority to decide which deserve mention next, and the resulting text is fed through TTS.
  • With 15 years of historical data, the game uses nearest-neighbor search to find similar past games and share insights.
  • It even goofs around - comparing the current playing style to past legends and sprinkling in a few locker-room whispers.

License and acknowledgements

This code is licensed under the MIT License.

The paddle-hitting sound was generated using SoundReality's "Tennis Ball Hit" sound.
It is licensed under Pixabay's "Content License".

The filler sounds were generated with https://www.openai.fm/ and abide by OpenAI's terms and policies.

联系我们 contact @ memedata.com