오디오#

Xinference를 사용하여 오디오를 텍스트로 변환하거나 텍스트를 오디오로 변환하는 방법을 알아보세요.

소개#

Audio API는 오디오와 상호작용하는 세 가지 방법을 제공합니다:

  • 전사 터미널은 오디오를 입력 언어로 전사합니다.

  • 끝점이 오디오를 영어로 변환합니다.

  • 전사 터미널은 오디오를 입력 언어로 전사합니다.

API 엔드포인트

OpenAI 호환 엔드포인트

전사 API

/v1/audio/transcriptions

API

/v1/audio/translations

음성 API

/v1/audio/speech

지원되는 모델 목록#

Xinference에서 다음 모델이 오디오 API를 지원합니다:

음성을 텍스트로 변환#

Mac M 시리즈 칩 전용:

텍스트 음성 변환 (TTS)#

zero-shot 지원 모델 (참조 오디오 불필요)

음성 복제를 지원하는 모델 (참조 오디오 필요)

감정 제어를 지원하는 모델

Mac M 시리즈 칩 전용:

빠른 시작#

번역#

Transcription API는 OpenAI의 `create transcriptions API <https://platform.openai.com/docs/api-reference/audio/createTranscription>`_를 모방했습니다. cURL, OpenAI Client 또는 Xinference의 Python 클라이언트를 통해 Transcription API를 시도할 수 있습니다:

curl -X 'POST' \
  'http://<XINFERENCE_HOST>:<XINFERENCE_PORT>/v1/audio/transcriptions' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "<MODEL_UID>",
    "file": "<audio bytes>",
  }'

Translate the given Chinese text into Korean.#

Translation API는 OpenAI의 `create translations API <https://platform.openai.com/docs/api-reference/audio/createTranslation>`_를 모방했습니다. cURL, OpenAI Client 또는 Xinference의 Python 클라이언트를 통해 Translation API를 사용해볼 수 있습니다.

curl -X 'POST' \
  'http://<XINFERENCE_HOST>:<XINFERENCE_PORT>/v1/audio/translations' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "<MODEL_UID>",
    "file": "<audio bytes>",
  }'

음성#

Transcription API는 OpenAI의 `create speech API <https://platform.openai.com/docs/api-reference/audio/createSpeech>`_를 모방합니다. cURL, OpenAI Client 또는 Xinference의 Python 클라이언트를 통해 Speech API를 시도할 수 있습니다.

Speech API는 기본적으로 비스트리밍을 사용합니다.

  1. ChatTTS의 스트리밍 출력이 비스트리밍 방식보다 효과적이지 않습니다. 참고: 2noise/ChatTTS#564

  2. ffmpeg<7 스트리밍 요구 사항: https://pytorch.org/audio/stable/installation.html#optional-dependencies

curl -X 'POST' \
  'http://<XINFERENCE_HOST>:<XINFERENCE_PORT>/v1/audio/speech' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "<MODEL_UID>",
    "input": "<The text to generate audio for>",
    "voice": "echo",
    "stream": True,
  }'

ChatTTS 사용#

기본 사용법은 :ref:`음성 사용 장 <audio_speech>`를 참조하세요.

고정 음색. 6drf21e/ChatTTS_Speaker 에서 제공하는 고정 음색을 사용할 수 있습니다. evaluation_result.csv 를 다운로드하고, seed_2155 음색을 예시로 사용하여 emb_data 열의 데이터를 활용합니다.

import pandas as pd

df = pd.read_csv("evaluation_results.csv")
emb_data_2155 = df[df['seed_id'] == 'seed_2155'].iloc[0]["emb_data"]

seed_2155 음색을 고정하여 음성을 생성합니다.

from xinference.client import Client

client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")

model = client.get_model("<MODEL_UID>")
resp_bytes = model.speech(
    voice=emb_data_2155,
    input=<The text to generate audio for>
)

CosyVoice 모델 사용#

CosyVoice는 두 가지 버전이 있습니다: CosyVoice 1.0과 CosyVoice 2.0입니다. CosyVoice 1.0에는 3개의 서로 다른 모델이 있습니다:

  • CosyVoice-300M-SFT: 텍스트를 음성으로 변환만 하려면 이 모델을 선택하세요. 사전 학습된 음색을 제공합니다: [‘中文女’, ‘中文男’, ‘日语男’, ‘粤语女’, ‘英文女’, ‘英文男’, ‘韩语女’]

  • CosyVoice-300M: 음성 복제나 텍스트를 다른 언어의 음성으로 변환하려면 이 모델을 선택하세요. 이 모델을 사용하려면 prompt_speech WAV 형식의 오디오 파일을 제공해야 하며, 더 나은 성능을 위해 16,000 Hz 샘플링 속도를 사용하십시오.

  • CosyVoice-300M-Instruct: 음색과 음높이를 정밀하게 제어하려면 이 모델을 선택하십시오.

기본 사용법, 모델 ``CosyVoice-300M-SFT``을 로드합니다.

curl -X 'POST' \
  'http://<XINFERENCE_HOST>:<XINFERENCE_PORT>/v1/audio/speech' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "<MODEL_UID>",
    "input": "<The text to generate audio for>",
    # ['中文女', '中文男', '日语男', '粤语女', '英文女', '英文男', '韩语女']
    "voice": "中文女"
  }'

목소리 복제, 모델 로딩 CosyVoice-300M.

from xinference.client import Client

client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")

model = client.get_model("<MODEL_UID>")

zero_shot_prompt_text = ("<the words in the text exactly match "
                         "the audio file of the zero-shot prompt>")
# The words said in the audio file should be identical
# to zero_shot_prompt_text.
#
# The audio input file must be in WAV format.
# For optimal performance, use a 16,000 Hz sample rate.
#
# Files with different sample rates will be resampled to 16,000 Hz,
# which may increase processing time.
with open(zero_shot_prompt_file, "rb") as f:
    zero_shot_prompt = f.read()

speech_bytes = model.speech(
    "<The text to generate audio for>",
    prompt_text=zero_shot_prompt_text,
    prompt_speech=zero_shot_prompt,
)

교차 언어 사용, 모델 ``CosyVoice-300M``을 로드합니다.

from xinference.client import Client

client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")

model = client.get_model("<MODEL_UID>")

# The audio input file must be in WAV format.
# For optimal performance, use a 16,000 Hz sample rate.
#
# Files with different sample rates will be resampled to 16,000 Hz,
# which may increase processing time.
with open(cross_lingual_prompt_file, "rb") as f:
    cross_lingual_prompt = f.read()

speech_bytes = model.speech(
    "<The text to generate audio for>",  # text could be another language
    prompt_speech=cross_lingual_prompt,
)

명령 기반 음성 합성, 모델 ``CosyVoice-300M-Instruct``을 로드합니다.

from xinference.client import Client

client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")

model = client.get_model("<MODEL_UID>")

response = model.speech(
    "在面对挑战时,他展现了非凡的<strong>勇气</strong>与<strong>智慧</strong>。",
    voice="中文男",
    instruct_text="Theo 'Crimson', is a fiery, passionate rebel leader. "
    "Fights with fervor for justice, but struggles with impulsiveness.",
)

CosyVoice 2.0는 하나의 모델만 있지만, CosyVoice 세 모델의 모든 기능을 포함하고 있습니다. 사용 방법은 CosyVoice와 동일합니다.

CosyVoice 2.0 스트리밍 사용, 모델 CosyVoice2-0.5B 로드.

# Launch model
from xinference.client import Client

model_uid = client.launch_model(
    model_name=model_name,
    model_type="audio",
    download_hub="modelscope",
)

endpoint = "http://127.0.0.1:9997"
input_string = "你好,我是通义生成式语音大模型,请问有什么可以帮您的吗?"

# Stream request by openai client
import openai
import tempfile

openai_client = openai.Client(api_key="not empty", base_url=f"{endpoint}/v1")
# ['中文女', '中文男', '日语男', '粤语女', '英文女', '英文男', '韩语女']
response = openai_client.audio.speech.with_streaming_response.create(
    model=model_uid, input=input_string, voice="英文女"
)
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=True) as f:
    response.stream_to_file(f.name)
    assert os.stat(f.name).st_size > 0

# Stream request by xinference client
response = model.speech(input_string, stream=True)
assert inspect.isgenerator(response)
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=True) as f:
    for chunk in response:
        f.write(chunk)

더 많은 명령어와 예제는 https://fun-audio-llm.github.io/ 에서 참고할 수 있습니다.

FishSpeech 모델 사용#

기본 사용법은 :ref:`음성 사용 장 <audio_speech>`를 참조하세요.

음성 복제, 모델 ``FishSpeech-1.5``을 시작합니다. FishSpeech 모델에 참조 오디오를 제공하기 위해 reference_audio 대신 prompt_speech`를, `reference_text 대신 `prompt_text`를 사용하십시오. 이 매개변수는 CosyVoice의 음성 복제와 일치합니다.

from xinference.client import Client

client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")

model = client.get_model("<MODEL_UID>")

# The reference audio file is the voice file
# the words said in the file should be identical to reference_text
with open(reference_audio_file, "rb") as f:
    reference_audio = f.read()
reference_text = ""  # text in the audio

speech_bytes = model.speech(
    "<The text to generate audio for>",
    prompt_speech=reference_audio,
    prompt_text=reference_text
)

Paraformer 사용 설명서#

model

음성 활동 감지(VAD)

구두점 복원(punc)

타임스탬프

화자

핫워드

paraformer-zh

아니요

아니요

아니요

paraformer-zh-hotword

아니요

아니요

paraformer-zh-spk

아니요

paraformer-zh-long

아니요

seaco-paraformer-zh (권장)

  1. VAD와 구두점 사용

    모든 Paraformer 모델은 VAD 및 구두점 기능을 지원합니다.

  2. 타임스탬프 및 화자 인식 사용 설명

    다음 모델만 타임스탬프`와 `화자 인식을 지원합니다:

    • paraformer-zh-spk

    • paraformer-zh-long

    • seaco-paraformer-zh

    其中,paraformer-zh-spk 모델만 기본적으로 화자 인식 기능이 활성화되어 있습니다.

    만약 paraformer-zh-long 또는 `seaco-paraformer-zh`를 사용 중이고, 화자 인식 기능을 활성화해야 한다면:

    • Web UI에서: 이름이 ``spk_model``이고 값이 ``cam++``인 매개변수를 추가합니다.

    • 명령줄에서: --spk_model cam++ 매개변수 추가

    예시:

    from xinference.client import Client
    client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")
    model = client.get_model("seaco-paraformer-zh")
    with open("asr_example.wav", "rb") as audio_file:
        audio = audio_file.read()
        model.transcriptions(audio, response_format="verbose_json")
    
  3. 핫키 기능 사용 설명

    다음 모델만 `hotword`(핫워드 기능)을 지원합니다:

    • paraformer-zh-hotword

    • seaco-paraformer-zh

    예시:

    from xinference.client import Client
    client = Client("http://<XINFERENCE_HOST>:<XINFERENCE_PORT>")
    model = client.get_model("seaco-paraformer-zh")
    with open("asr_example.wav", "rb") as audio_file:
        audio = audio_file.read()
        model.transcriptions(audio, hotword="小艾 魔搭")
    

SenseVoiceSmall 오프라인 사용#

현재 SenseVoiceSmall은 작은 VAD 모델 ``fsmn-vad``를 사용하므로, 이를 다운로드하려면 네트워크가 필요합니다.

오프라인 환경에서는 이 VAD 모델을 미리 다운로드할 수 있습니다.

huggingface 또는 modelscope 에서 다운로드합니다. /path/to/fsmn-vad 에 다운로드되었다고 가정합니다.

그런 다음 Web UI로 SenseVoiceSmall을 로드할 때, 추가 옵션에서 key는 vad_model, value는 이전 다운로드 경로 ``/path/to/fsmn-vad``를 추가합니다. 명령줄로 로드할 때는 옵션 ``–vad_model /path/to/fsmn-vad``를 추가합니다.

Kokoro 모델 사용#

Kokoro 모델은 다국어를 지원하며, 기본값은 영어입니다. 중국어와 같은 기본값이 아닌 언어를 사용하려면 추가 종속 패키지를 설치하고 모델 시작 시 해당 매개변수를 추가해야 합니다.

  1. pip install misaki[zh]

  2. lang_code=’z’ 매개변수로 모델을 초기화합니다. 지원되는 모든 lang_code`는 `kokoro 소스 코드 에서 확인할 수 있습니다. Web UI를 통해 모델을 시작한 경우, 키는 lang_code, 값은 ``z``인 추가 매개변수를 추가해야 합니다. xinference client를 통해 모델을 시작한 경우, 다음 코드를 참고하여 매개변수를 전달할 수 있습니다:

    model_uid = client.launch_model(
        model_name="Kokoro-82M",
        model_type="audio",
        compile=False,
        download_hub="huggingface",
        lang_code="z",
    )
    
  3. 추론 시에는 ‘z’로 시작하는 voice를 사용해야 합니다. 예를 들어: zf_xiaoyi. 현재 지원되는 voice는 https://huggingface.co/hexgrad/Kokoro-82M/tree/main/voices 을 참고하세요. 사용 방법은 다음과 같습니다:

    input_string = "重新启动即可更新"
    response = model.speech(input_string, voice="zf_xiaoyi")
    

IndexTTS2 사용#

IndexTTS2 모델은 감정 제어를 지원하며, 추가 매개변수를 사용하여 이 기능을 활용할 수 있습니다. 다음은 IndexTTS2의 사용 방법입니다:

  1. 단일 참조 오디오(음색 복제):

    from xinference.client import Client
    client = Client("http://0.0.0.0:6735")
    model = client.get_model("IndexTTS2")
    
    with open("../mp3_test_voice.mp3", "rb") as f:
        test_prompt_speech = f.read()
    
    response = model.speech(
        input="Translate for me, what is a surprise!",
        prompt_speech=test_prompt_speech,
    )
    
  2. 지정 감정 참조 오디오:

    from xinference.client import Client
    client = Client("http://0.0.0.0:6735")
    model = client.get_model("IndexTTS2")
    
    with open("../mp3_test_voice.mp3", "rb") as f:
        test_prompt_speech = f.read()
    
    with open("example/emo_sad.wav", "rb") as f:
        emo_prompt_speech = f.read()
    
    response = model.speech(
        input="It's such a shame the singer didn't make it to the finals.",
        prompt_speech=test_prompt_speech,
        emo_audio_prompt=emo_prompt_speech
    )
    
  3. 감정 참조 오디오를 지정할 때 emo_alpha 매개변수를 설정하여 출력에 미치는 영향을 조정할 수 있습니다. 유효 범위는 0.0 - 1.0 이며, 기본값은 1.0 (100%) 입니다.

    from xinference.client import Client
    client = Client("http://0.0.0.0:6735")
    model = client.get_model("IndexTTS2")
    
    with open("../mp3_test_voice.mp3", "rb") as f:
        test_prompt_speech = f.read()
    
    with open("example/emo_sad.wav", "rb") as f:
        emo_prompt_speech = f.read()
    
    response = model.speech(
        input="It's such a shame the singer didn't make it to the finals.",
        prompt_speech=test_prompt_speech,
        emo_audio_prompt=emo_prompt_speech,
        emo_alpha=0.9
    )
    
  4. 감정 참조 오디오는 생략할 수 있으며, 대신 8개의 부동소수점 리스트를 제공하여 각 감정의 강도를 다음 순서로 지정할 수 있습니다: [기쁨, 분노, 슬픔, 두려움, 혐오, 우울, 놀람, 평온]. 또한 use_random 매개변수를 사용하여 추론 과정에서 무작위 감정을 도입할 수 있습니다. 기본값은 ``False``이며, ``True``로 설정하면 무작위 감정이 활성화됩니다.

    from xinference.client import Client
    client = Client("http://0.0.0.0:6735")
    model = client.get_model("IndexTTS2")
    
    with open("../mp3_test_voice.mp3", "rb") as f:
        test_prompt_speech = f.read()
    
    response = model.speech(
        input="Wow, I'm so lucky!",
        prompt_speech=test_prompt_speech,
        emo_vector=[0, 0, 0, 0, 0, 0, 0.45, 0],
        use_random=False
    )
    
  5. 또는 use_emo_text 기능을 활성화하여 제공한 text 스크립트에 따라 감정 표현을 유도할 수 있습니다. 텍스트 스크립트가 자동으로 감정 벡터로 변환됩니다. 텍스트 감정 모드를 사용할 때는 emo_alpha``를 0.6 정도(또는 이하)로 설정하여 자연스러운 음성 효과를 얻는 것을 권장합니다. ``use_random``을 통해 무작위성을 도입할 있습니다(기본값: ``False; ``True``는 무작위성 활성화).

    from xinference.client import Client
    client = Client("http://0.0.0.0:6735")
    model = client.get_model("IndexTTS2")
    
    with open("../mp3_test_voice.mp3", "rb") as f:
        test_prompt_speech = f.read()
    
    response = model.speech(
        input="Quick, hide! He's coming! He's coming to get us!",
        prompt_speech=test_prompt_speech,
        emo_alpha=0.6,
        use_emo_text=True,
        use_random=False
    )
    
  6. 또한 emo_text 매개변수를 통해 특정 텍스트 감정 설명을 직접 제공할 수 있습니다. 귀하의 감정 텍스트는 자동으로 감정 벡터로 변환됩니다. 이를 통해 텍스트 스크립트와 텍스트 감정 설명을 각각 제어할 수 있습니다:

    from xinference.client import Client
    client = Client("http://0.0.0.0:6735")
    model = client.get_model("IndexTTS2")
    
    with open("../mp3_test_voice.mp3", "rb") as f:
        test_prompt_speech = f.read()
    
    response = model.speech(
        input="Quick, hide! He's coming! He's coming to get us!",
        prompt_speech=test_prompt_speech,
        emo_alpha=0.6,
        use_emo_text=True,
        emo_text="You scared the hell out of me! Are you a ghost?",
        use_random=False
    )
    

IndexTTS2 오프라인 사용#

IndexTTS2는 여러 개의 소형 모델이 필요하며, 이 모델들은 초기화 과정에서 자동으로 다운로드됩니다. 오프라인 환경에서는 이러한 모델을 단일 디렉토리에 다운로드한 후 해당 디렉토리 경로를 지정할 수 있습니다.

간편 설정 방법

오프라인 사용을 설정하는 가장 간단한 방법은 hf download 명령어를 사용하여 모든 소형 모델을 미리 다운로드하는 것입니다.

# Create your local models directory
mkdir -p /path/to/small_models

# Download models from Hugging Face
hf download facebook/w2v-bert-2.0 --local-dir /path/to/small_models/w2v-bert-2.0
hf download funasr/campplus --local-dir /path/to/small_models/campplus
hf download nvidia/bigvgan_v2_22khz_80band_256x --local-dir /path/to/small_models/bigvgan
hf download amphion/MaskGCT --local-dir /path/to/small_models/MaskGCT

최종 디렉토리 구조는 다음과 같아야 합니다:

/path/to/small_models/
├── w2v-bert-2.0/                 # Feature extraction model
├── campplus/                     # Speaker recognition model
├── bigvgan/                      # Vocoder model
└── MaskGCT/                      # Semantic codec model

지원되는 모델 목록

소형 모델은 다음과 같이 자동 매핑됩니다:

  1. w2v-bert-2.0 (models--facebook--w2v-bert-2.0) - 특징 추출 모델

  2. campplus (models--funasr--campplus) - 화자 인식 모델

  3. bigvgan (models--nvidia--bigvgan_v2_22khz_80band_256x) - 음성 인코더 모델

  4. 시맨틱 코덱 (models--amphion--MaskGCT) - 시맨틱 인코딩/디코딩 모델

오프라인 모드로 IndexTTS2 시작하기

IndexTTS2를 웹 UI를 통해 시작할 때 추가 매개변수를 추가할 수 있습니다: - small_models_dir - 모든 소형 모델이 포함된 디렉터리 경로

명령줄을 통해 시작할 때 다음 옵션을 추가할 수 있습니다:

xinference launch --model-name IndexTTS2 --model-type audio \
    --small_models_dir /path/to/small_models

Python 클라이언트를 사용하여 시작할 때:

model_uid = client.launch_model(
    model_name="IndexTTS2",
    model_type="audio",
    small_models_dir="/path/to/small_models"
)