我用castv2-client和google-tts-api通过ip地址输出音频信息到我的google home。它工作正常,但是音量有点大,我不知道如何降低音量。如果我在google home上手动降低音量,应用程序会覆盖它,它仍然很大。我怎么才能把音量设置得更低?
此外,console. log("VOLUME",音量)输出
{
controlType: 'master',
level: 1,
muted: false,
stepInterval: 0.019999999552965164
}
var Client = require("castv2-client").Client;
var DefaultMediaReceiver = require("castv2-client").DefaultMediaReceiver;
const googleTTS = require("google-tts-api");
var cron = require("node-cron");
function broadcastMessage(message) {
var App = {
playin: false,
DeviceIp: "",
Player: null,
GoogleHome: function (host, url) {
var client = new Client();
client.connect(host, function () {
client.launch(DefaultMediaReceiver, function (err, player) {
client.setVolume({ level: 1 }, function (err, volume) {
console.log("VOLUME", volume);
if (err) {
// Handle error as appropriate
console.log("Error on setVolume:", err);
} else {
console.log("Sending new alert");
}
});
var media = {
contentId: url,
contentType: "audio/mp3",
streamType: "BUFFERED",
};
App.Player = player;
App.Player.load(media, { autoplay: true }, function (err, status) {
App.Player.on("status", function (status) {
if (status.playerState === "IDLE" && App.playin === false) {
client.close();
}
});
});
});
});
client.on("error", function (err) {
console.log("Error: %s", err.message);
client.close();
});
},
run: function (ip, text) {
App.DeviceIp = ip;
const url = googleTTS.getAudioUrl(text, {
lang: "en-US",
slow: false,
host: "https://translate.google.com",
});
App.GoogleHome(App.DeviceIp, url, function (res) {
console.log(res);
});
},
broadcast: function (text) {
const ip = "192.168.0.17";
App.run(ip, text);
},
};
App.broadcast(message);
setTimeout(() => {
App.broadcast(message);
}, 4000);
}
module.exports = {
broadcastMessage,
};
broadcastMessage("Incoming message");
2条答案
按热度按时间92dk7w1h1#
据我所知,你在代码中设置了音量为
1
,这是最大音量,所以你的音频将以最大音量播放,这是你设置音量的地方:只需删除此代码,您的消息将以您在设备上手动设置的音量播放。
另外:如果您打算设置设备的音量,则应等待回调返回,然后才发送消息。
i86rm4rw2#
解决方案是我必须在
client.setVolume({ level: 1 }
调用之前定义值,所以基本上