SoundCloneTest.go 1.14 KB
Newer Older
Ford committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

// 创建请求参数的结构体
type ModelSettings struct {
	GptModelPath    string `json:"gpt_model_path"`
	SovitsModelPath string `json:"sovits_model_path"`
}

// 设置音色模型的函数
func setModel() {
	// 设置请求的URL
	url := "http://58.34.54.45:17666/set_model"

	// 构造请求体
	settings := ModelSettings{
		GptModelPath:    "/psycheEpic/GPT-SoVITS/GPT_weights/huainvren-e20.ckpt",
		SovitsModelPath: "/psycheEpic/GPT-SoVITS/SoVITS_weights/huainvren_e51_s816.pth",
	}

	// 将结构体转换为JSON格式的字节切片
	requestBody, err := json.Marshal(settings)
	if err != nil {
		fmt.Println("Error marshalling JSON: ", err)
		return
	}

	// 创建POST请求
	resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody))
	if err != nil {
		fmt.Println("Error sending request: ", err)
		return
	}
	defer resp.Body.Close()

	// 读取并打印响应体
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response body: ", err)
		return
	}

	fmt.Println("Response:", string(body))
}

func main() {
	setModel()
}