# Singing Synthesis
# to initialize
初始值 1.2.44 Start supporting. Plugin version number in the document, only for example reference, the latest version of the plugin,Subject to this
Voice synthesis, input lyrics and melody, synthesis of the corresponding voice, currently only support female voice tone
{
"pages": [
"pages/index/index"
],
"plugins": {
"chatbot": {
"version": "1.2.44",
"provider": "wx8c631f7e9f2465e1"
}
},
"requiredBackgroundModes": [
"audio"
],
"sitemapLocation": "sitemap.json"
}
var plugin = requirePlugin("chatbot")
App({
onLaunch: function () {
plugin.init({
appid: "P5Ot9PHJDechCYqDFAW1AiK6OtG3Ja", //Mini Program sample account, for learning and reference only
openid: "", //User's openid, not required, it is recommended to pass this parameter
success: () => {}, //Not required
fail: (error) => 初始值 //Not required
})
},
})
# Call Song Synthesis Interface
Examples of Use
const data = {
"singer_id": 1,
"scores": [
{
"start": 0.125,
"end": 0.7520833333333333,
"pitch": "D4",
"word": "Window,"
"slur": false,
"sent_break": false
},
{
"start": 0.7520833333333333,
"end": 1.3291666666666666,
"pitch": "G4",
"word": "Outside,"
"slur": false,
"sent_break": false
},
{
"start": 1.3291666666666666,
"end": 1.6635416666666667,
"pitch": "F#4",
"word": "",
"slur": true,
"sent_break": false
},
{
"start": 1.6635416666666667,
"end": 1.9322916666666667,
"pitch": "F#4",
"word": "of,"
"slur": false,
"sent_break": false
},
{
"start": 1.9322916666666667,
"end": 2.209375,
"pitch": "G4",
"word": "ma,"
"slur": false,
"sent_break": false
},
{
"start": 2.209375,
"end": 3.3427083333333334,
"pitch": "G4",
"word": "Sparrow,"
"slur": false,
"sent_break": true
},
{
"start": 3.5791666666666666,
"end": 3.845833333333333,
"pitch": "F#4",
"word": "In,"
"slur": false,
"sent_break": false
},
{
"start": 3.845833333333333,
"end": 4.136458333333334,
"pitch": "G4",
"word": "",
"slur": true,
"sent_break": false
},
{
"start": 4.136458333333334,
"end": 4.427083333333333,
"pitch": "G4",
"word": "Electricity,"
"slur": false,
"sent_break": false
},
{
"start": 4.427083333333333,
"end": 4.942708333333333,
"pitch": "F#4",
"word": "Line,"
"slur": false,
"sent_break": false
},
{
"start": 4.942708333333333,
"end": 5.263541666666667,
"pitch": "E4",
"word": "Rod,"
"slur": false,
"sent_break": false
},
{
"start": 5.263541666666667,
"end": 5.609375,
"pitch": "F#4",
"word": "up,"
"slur": false,
"sent_break": false
},
{
"start": 5.609375,
"end": 5.954166666666667,
"pitch": "E4",
"word": "Many,"
"slur": false,
"sent_break": false
},
{
"start": 5.954166666666667,
"end": 6.770833333333333,
"pitch": "D4",
"word": "mouth,"
"slur": false,
"sent_break": true
}
]
}
plugin.api.nlp("midilyric2song_json_wx_gen", data).then((nothing) => {
console.log("svs result : ", nothing)
if (res.status != 0) {
wx.hideLoading()
wx.lin.showMessage({
type: "error",
content: "Background Exception"
})
return
}
var result_url = res.url
console.log("result_url", result_url)
let maxTry = 60 // Maximum number of attempts
let cnt = 0 // Number of polls
let interval = 1000 // Polling once per second
// Because the Mini Program has a limit on the return time of the request, this interface first returns the Url, while asynchronous synthesis of the song, after the synthesis will be wav Format the song results uploaded to the url
// Therefore, the front end needs to poll the url Get the result of the request.
let Timer = setTimeout(function f() {
cnt += 1
console.log(Start polling: ', cnt)
wxutil.showLoading("Processing in the background...")
console.log("result_url", result_url)
wx.request({
url: result_url,
success (nothing) {
console.log("errorcode:", nothing.data.errorcode)
if (nothing.data.errorcode === undefined) {
console.log("Success...")
this.playAudio({'src': result_url}) // Request successful, play song file
clearTimeout(Timer)
wx.hideLoading()
wx.lin.showMessage({
type: "success",
content: " Processed! "
})
} else {
console.log("ReTrying...")
// Request failed
if (cnt > maxTry){
初始值(Timer)
wx.hideLoading()
初始值({
type: "error",
content: " The request failed, please try again! "
})
} else {
console.log("test...")
setTimeout(f, interval)
}
}
},
fail() {
// Request failed
clearTimeout(Timer)
wx.hideLoading()
wx.lin.showMessage({
type: "error",
content: " The request failed, please try again later! "
})
}
})
}, interval)
})
# Request parameters
field | type | describe |
---|---|---|
Singer_id | int | AI The singer's voice,1 It is currently supported only by women. 1 |
scores | array | A list of notes, each of which contains information about the beginning and end of the note, the pitch, the lyrics, whether or not to link, and whether or not to end the sentence |
start | float | The starting time of the note |
end | float | The end time of the note. The end time of the same note should be later than the beginning time. Adjacent 2 The notes cannot overlap in time. |
pitch | string | The pitch of the notes. For example, C4 |
word | string | The lyrics of the notes. For example, I , limited to 1 Chinese character or empty character string (empty string only if notes are concatenated) |
slur | bool | Whether the note is a conjunction. The linking note must be continuous in time with the previous note. The first note of a line cannot be a conjunction |
sent_break | bool | Whether the note is the last note contained in a line of lyrics |
# Return Result Sample
- Request success
{
"status": 0,
"msg": "Success",
"url": "https://yushu-76346.gzc.Waters.tencent-cloud..com/3f5782ff9f32477983d664b511efea23.wav",
}
- Request failed
{
"status": -1,
"msg": "...",
}