add /tts - #343
Conversation
add /tts
add config of TTS
There was a problem hiding this comment.
Summary of Changes
Hello @TamHC, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a new text-to-speech (TTS) feature, enabling users to generate spoken audio from text using a /tts command. It integrates with the OpenAI TTS API, provides comprehensive configuration options for customization, and updates the bot's command handling and documentation to support this new functionality.
Highlights
- New
/ttsCommand: Users can now convert written text into spoken audio directly via a new/ttscommand, enhancing the bot's interactive capabilities. - Configurable TTS Settings: New configuration options (
TTS_API_BASE,TTS_API_KEY,TTS_MODEL,TTS_VOICE,TTS_MODELS_LIST,TTS_VOICES_LIST) have been introduced, allowing for extensive customization of the text-to-speech experience. - OpenAI TTS API Integration: The core text-to-speech functionality is powered by the OpenAI TTS API, with a dedicated
OpenAITTSclass handling requests, API key management, and model/voice selection. - Multi-language Command Help: The usage and description for the new
/ttscommand have been added to the help texts in English, Simplified Chinese, and Traditional Chinese, improving accessibility for a wider user base.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
The pull request introduces a new /tts command that allows users to convert text to speech. It includes configuration options, API integration with OpenAI's TTS models, and command handling logic. The code appears well-structured and implements the new functionality effectively.
| class TTSConfig { | ||
| TTS_API_BASE = "https://api.openai.com/v1"; | ||
| TTS_API_KEY = []; | ||
| TTS_MODEL = "tts-1"; | ||
| TTS_VOICE = "alloy"; | ||
| TTS_MODELS_LIST = '["tts-1", "tts-1-hd", "gpt-4o-mini-tts"]'; | ||
| TTS_VOICES_LIST = '["alloy", "echo", "fable", "nova", "onyx", "shimmer", "ash", "ballad", "coral", "sage"]'; | ||
| } |
There was a problem hiding this comment.
Consider adding a brief description for each property in the TTSConfig class to improve readability and maintainability.
class TTSConfig {
// Base URL for the TTS API
TTS_API_BASE = "https://api.openai.com/v1";
// API Key(s) for the TTS API
TTS_API_KEY = [];
// Model to use for TTS
TTS_MODEL = "tts-1";
// Voice to use for TTS
TTS_VOICE = "alloy";
// List of available TTS models
TTS_MODELS_LIST = '["tts-1", "tts-1-hd", "gpt-4o-mini-tts"]';
// List of available TTS voices
TTS_VOICES_LIST = '["alloy", "echo", "fable", "nova", "onyx", "shimmer", "ash", "ballad", "coral", "sage"]';
}| @@ -127,10 +136,10 @@ class EnvironmentConfig { | |||
| DEBUG_MODE = false; | |||
There was a problem hiding this comment.
Consider adding the tts command to the other language translations as well.
const pt = { "env": { "system_init_message": "Você é um assistente útil" }, "command": { "help": { "summary": "Os seguintes comandos são suportados atualmente:\n", "help": "Obter ajuda sobre comandos", "new": "Iniciar uma nova conversa", "start": "Obter seu ID e iniciar uma nova conversa", "img": "Gerar uma imagem, o formato completo do comando é `/img descrição da imagem`, por exemplo `/img praia ao luar`", "tts": "Gerar áudio de fala, formato `/tts [voz] conteúdo do texto`, por exemplo `/tts alloy Olá Mundo`", "version": "Obter o número da versão atual para determinar se é necessário atualizar", "setenv": "Definir configuração do usuário, o formato completo do comando é /setenv CHAVE=VALOR", "setenvs": 'Definir configurações do usuário em lote, o formato completo do comando é /setenvs {"CHAVE1": "VALOR1", "CHAVE2": "VALOR2"}', "delenv": "Excluir configuração do usuário, o formato completo do comando é /delenv CHAVE", "clearenv": "Limpar todas as configurações do usuário", "system": "Ver algumas informações do sistema", "redo": "Refazer a última conversa, /redo com conteúdo modificado ou diretamente /redo", "echo": "Repetir a mensagem", "models": "Mudar o modelo de diálogo" }, "new": { "new_chat_start": "Uma nova conversa foi iniciada" } }, "callback_query": { "open_model_list": "Abra a lista de modelos", "select_provider": "Escolha um fornecedor de modelos.:", "select_model": "Escolha um modelo:", "change_model": "O modelo de diálogo já foi modificado para" } };| if (message.chat.type === "group" || message.chat.type === "supergroup") { | ||
| params.reply_parameters = { | ||
| message_id: message.message_id, | ||
| chat_id: message.chat.id, | ||
| allow_sending_without_reply: true | ||
| }; | ||
| } |
There was a problem hiding this comment.
Consider simplifying this conditional logic by directly assigning the reply_parameters object based on the chat type.
const params = {
chat_id: message.chat.id,
voice: audioBlob,
caption: `🎵 語音:${voice}\n📝 文字:${text.length > 100 ? text.substring(0, 100) + '...' : text}`,
...(message.chat.type === "group" || message.chat.type === "supergroup") && {
reply_parameters: {
message_id: message.message_id,
chat_id: message.chat.id,
allow_sending_without_reply: true
}
}
};add /tts
Integrating the /tts command, allowing users to convert written text into spoken audio.
Updated the related configuration to customize the TTS experience according to user preferences.