KeiStory

반응형

Qwen3-TTS 사용해 보기

 

조코딩에서 소개하기에 한국어도 지원되서 한번 실행해 봤는데 생각보다 좋은 결과가 나와 소개해봅니다.

특히 목소리 스타일을 자연어로 지정할 수 있다는 점이 큰 장점 입니다.

 

Qwen3-TTS 간단 요약

500만 시간 규모 학습 데이터
12Hz 초저지연 토크나이저
텍스트 + 음성 + 스타일을 아우르는 Omni-Audio 오픈소스 모델
대본 기반 나레이션, 유튜브 음성, 설명 영상에 활용도 높음

 

가상환경 설정

특정 폴더를 만들고 cmd 창에서 아래 명령을 실행합니다.

python -m venv venv
.\venv\Scripts\activate

 

Qwen3-TTS 설치

가상환경이 활성화된 상태에서 아래 명령으로 설치합니다.

pip install -U qwen-tts

 

코드 작성

GPU 환경(CUDA)을 기준으로 테스트한 예제 코드입니다.

import torch
import soundfile as sf
from qwen_tts import Qwen3TTSModel

print(torch.cuda.is_available())
print(torch.version.cuda)

# 1. 모델 로드
# Hugging Face 모델 ID를 통해 자동으로 가중치를 다운로드하고 로드합니다.
model = Qwen3TTSModel.from_pretrained(
    "Qwen/Qwen3-TTS-12Hz-1.7B-VoiceDesign",
    device_map="cuda:0",               # GPU 사용 설정
    dtype=torch.bfloat16              # 데이터 타입 설정
    #attn_implementation="flash_attention_2", # FlashAttention 2 사용 (설치된 경우)
)

# 2. 음성 생성 (Voice Design)
# instruct 파라미터에 원하는 목소리의 특징을 자연어로 묘사합니다.
text = "안녕하세요? 저는 텍스트 설명만으로 만들어진 새로운 목소리입니다."
instruct = "밝고 활기찬 여성 아이 목소리"

wavs, sr = model.generate_voice_design(
    text=text,          # 음성으로 변환할 입력 텍스트입니다.
    language="Korean",  # 언어 설정 (Auto로 설정 가능하나 명시 권장, 예: "Korean", "English", "Chinese" 등)
    instruct=instruct   # 목소리 묘사 프롬프트 (생성할 목소리의 성별, 연령, 톤, 스타일 등을 설명)
)

# 3. 결과 저장
sf.write("output_voice_design_child.wav", wavs[0], sr)
print("생성 완료: output_voice_design_child.wav")

 

실행 중 참고 사항

flash-attn 미설치 시 경고 메시지는 출력되지만 실행에는 문제 없습니다.

SoX could not be found 경고가 나오면 SoX 설치 또는 PATH 등록 필요하나 단순 WAV 저장은 큰 문제 없이 진행됩니다.

 

결과물

차분하고 신뢰감 있는 중저음의 남성 뉴스 앵커 목소리, 전문적인 톤.

output_voice_design.wav
0.30MB

밝고 활기찬 여성 아이 목소리

output_voice_design_child.wav
0.28MB

차분하고 신뢰감 있는 여성 뉴스 앵커 목소리, 전문적인 톤.

output_voice_design_woman.wav
0.34MB

데모사이트에서 만든 파일 (감정도 표현이 가능합니다.)
목소리설명: Speak in an incredulous tone, but with a hint of panic beginning to creep into your voice.

영어 (It's in the top drawer... wait, it's empty? No way, that's impossible! I'm sure I put it there!)

audio.wav
0.35MB

한글(맨 윗 서랍에 있는데... 잠깐, 비어있네? 말도 안 돼, 그럴 리가 없어! 분명 내가 넣어뒀는데!)

audio (1).wav
0.37MB

 

GPU 문제 발생하는 경우

실행시 문제가 되는 경우 아래 명령으로 torch 를 삭제하고 재설치합니다.

pip uninstall torch torchvision torchaudio -y

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
Looking in indexes: https://download.pytorch.org/whl/cu121

 

참고

Qwen3-TTS 소개
https://discuss.pytorch.kr/t/qwen3-tts-500-12hz-omni-audio/8817

 

Qwen3-TTS: 500만 시간의 학습 데이터, 12Hz 초저지연 토크나이저로 완성한 오픈소스 Omni-Audio 모델

Qwen3-TTS 모델 개요 Alibaba의 Qwen 팀은 최근 텍스트-음성 변환(TTS) 기술의 새로운 지평을 여는 Qwen3-TTS 시리즈를 전격 공개했습니다. 최근 인공지능 분야에서는 GPT-4o와 같이 텍스트, 오디오, 이미지

discuss.pytorch.kr

데모사이트
https://huggingface.co/spaces/Qwen/Qwen3-TTS?utm_source=pytorchkr&ref=pytorchkr

 

Qwen3-TTS Demo - a Hugging Face Space by Qwen

This app converts written text into realistic human-like speech. Users can choose from three methods: create entirely new voices using descriptive text, clone existing voices from audio samples, or...

huggingface.co

 

728x90

공유하기

facebook twitter kakaoTalk kakaostory naver band