Code Monkey home page Code Monkey logo

Comments (2)

pk5ls20 avatar pk5ls20 commented on June 30, 2024 1

as so on

稍微改动一下TTS/playground.py即可。
下面是一个简单的改动后示例,可以输入文字生成wav语音文件,请将这段代码放到TTS文件夹下运行

import wave
import numpy as np
import pyaudio


def generateAudio(speakContent: str, output_file: str) -> None:
    config_combo = [("models/paimon6k.json", "models/paimon6k_390k.pth")]
    for cfg, model in config_combo:
        a = TTService(cfg, model, 'test', 1)
        p = pyaudio.PyAudio()
        audio = a.read(speakContent)
        stream = p.open(format=pyaudio.paFloat32, channels=1,
                        rate=a.hps.data.sampling_rate, output=True)
        data = audio.astype(np.float32).tostring()
        stream.write(data)
        # Set the audio properties
        num_channels = 1
        sample_width = 2  # Assuming 16-bit audio
        frame_rate = a.hps.data.sampling_rate
        # Convert audio data to 16-bit integers
        audio_int16 = (audio * np.iinfo(np.int16).max).astype(np.int16)
        # Open the output file in write mode
        with wave.open(output_file, 'wb') as wav_file:
            # Set the audio properties
            wav_file.setnchannels(num_channels)
            wav_file.setsampwidth(sample_width)
            wav_file.setframerate(frame_rate)
            # Write audio data to the file
            wav_file.writeframes(audio_int16.tobytes())


if __name__ == '__main__':
    import sys
    sys.path.append('vits')
    from TTService import TTService
    generateAudio("你好啊,我是派蒙", "output.wav")

from digital_life_server.

zixiiu avatar zixiiu commented on June 30, 2024

使用TTService对象就可以直接用,可以参考TTS/playground.py

from digital_life_server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.