Skip to main content

Discord 봇을 위한 TTS(Text-to-Speech) 라이브러리

Project description

Discord TTS

Discord 봇을 위한 다국어 TTS(Text-to-Speech) 라이브러리입니다.

설치 방법

pip install discord-tts

주요 기능

  • 다국어 지원 (한국어, 영어, 일본어, 중국어 등)
  • 음성 속도 조절
  • 음량 조절
  • 고급 텍스트 필터링
    • 정규식 기반 패턴 매칭
    • 기본 패턴 지원 (한글, 영문, 숫자, 특수문자, URL, 멘션, 이모지)
    • 사용자 정의 패턴 추가
    • 패턴 제거/유지 옵션
    • 최대 길이 제한
  • 임시 파일 자동 관리
  • 음성 채널 관리

사용 예시

기본 사용법

import discord
from discord.ext import commands
from discord_tts import TTSManager

bot = commands.Bot(command_prefix='!')

@bot.command()
async def tts(ctx, *, text):
    # TTS 매니저 초기화
    tts_manager = TTSManager()
    
    # 사용자의 음성 채널 확인
    if not ctx.author.voice:
        await ctx.send("음성 채널에 먼저 입장해주세요!")
        return
        
    # 봇이 음성 채널에 없으면 입장
    if not ctx.voice_client:
        await ctx.author.voice.channel.connect()
        
    # TTS 재생
    try:
        await tts_manager.play_tts(
            text=text,
            voice_client=ctx.voice_client
        )
    except Exception as e:
        await ctx.send(f"오류가 발생했습니다: {str(e)}")

bot.run('YOUR_BOT_TOKEN')

다국어 지원

# 영어로 TTS 재생
await tts_manager.play_tts(
    text="Hello, World!",
    voice_client=voice_client,
    lang='en'
)

# 일본어로 TTS 재생
await tts_manager.play_tts(
    text="こんにちは",
    voice_client=voice_client,
    lang='ja'
)

음성 속도와 음량 조절

# 느린 속도로 재생
await tts_manager.play_tts(
    text="안녕하세요",
    voice_client=voice_client,
    slow=True
)

# 음량 조절 (0.0 ~ 1.0)
await tts_manager.play_tts(
    text="안녕하세요",
    voice_client=voice_client,
    volume=0.5
)

텍스트 필터링

from discord_tts import clean_text

# 기본 필터링 (특수문자, 이모지, URL, 멘션 제거)
text = clean_text("안녕하세요! @user https://example.com 😊")
# 결과: "안녕하세요"

# 한글만 유지
text = clean_text(
    "안녕하세요! Hello World! 123",
    keep_patterns=['korean']
)
# 결과: "안녕하세요"

# 숫자만 유지
text = clean_text(
    "전화번호는 010-1234-5678입니다",
    keep_patterns=['numbers']
)
# 결과: "01012345678"

# URL과 멘션 제거
text = clean_text(
    "안녕하세요! @user https://example.com",
    remove_patterns=['url', 'mention']
)
# 결과: "안녕하세요!"

# 사용자 정의 패턴 추가
custom_patterns = {
    'phone': r'\d{3}-\d{4}-\d{4}',  # 전화번호 패턴
    'email': r'[\w\.-]+@[\w\.-]+'   # 이메일 패턴
}
text = clean_text(
    "연락처: 010-1234-5678, 이메일: test@example.com",
    patterns=custom_patterns,
    keep_patterns=['phone', 'email']
)
# 결과: "010-1234-5678 test@example.com"

# 최대 길이 제한
text = clean_text("안녕하세요!", max_length=5)
# 결과: "안녕하세"

지원하는 언어 목록 확인

tts_manager = TTSManager()
supported_languages = tts_manager.get_supported_languages()
print(supported_languages)

지원하는 언어

  • 한국어 (ko)
  • 영어 (en)
  • 일본어 (ja)
  • 중국어 간체 (zh-CN)
  • 중국어 번체 (zh-TW)
  • 스페인어 (es)
  • 프랑스어 (fr)
  • 독일어 (de)
  • 러시아어 (ru)
  • 포르투갈어 (pt)
  • 이탈리아어 (it)
  • 힌디어 (hi)
  • 아랍어 (ar)

라이선스

MIT License

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

discord-tts-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discord_tts-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file discord-tts-0.1.0.tar.gz.

File metadata

  • Download URL: discord-tts-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for discord-tts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6abf7788e0f57033604fe6045d4a67bd01a6edf3cbd7e3ca87728f3642e41d2f
MD5 ad670d2806c4661e9731c958421710dc
BLAKE2b-256 2b3695e4e60caf36a351b2cad26f03371bbd53d70a793b72ce477e1363dfb0ee

See more details on using hashes here.

File details

Details for the file discord_tts-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: discord_tts-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for discord_tts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d771ee357d542f101a50b5fdfbca1886e681a410d985c733a6a25d5965acf24f
MD5 75bef46c76b355e5b95597683a749ffd
BLAKE2b-256 51a257324e382446dbfde0c813045be8da4d4ee53a506c233bf0060d40260b3c

See more details on using hashes here.

Supported by

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