如何在 kde 等离子菜单中使用 tts 服务?
How to use tts service in a kde plasma menu?
我fork了EQMenu fork,我改变了外观,但是现在我想用tts软件告诉项目名称,所以我写了这个,但是错误在哪里?
我试图找到一种方法来做到这一点,现在我试试这个:
在菜单中,逻辑是由以下人员创建的:
tools.js
function tospeak(TextToSpeech) {
var process = require('child_process');
process.exec('/etc/alternatives/tts'+TextToSpeech,function (err,stdout,stderr) {
if (err) {
console.log("\n"+stderr);
} else {
console.log(stdout);
}
});
}
/etc/alternatives/tts选择不同的tts软件
在这个文件中是菜单的QML代码:
ItemGridDelegate.qml
-
import "../code/tools.js" as Tools
-
-
PlasmaCore.IconItem {
id: icon
y: showLabel ? (2 * highlightItemSvg.margins.top) : 0
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: showLabel ? undefined : parent.verticalCenter
width: mouseArea.containsMouse ? iconSize*1.25 : iconSize
height: width
animated: false
usesPlasmaTheme: item.GridView.view.usesPlasmaTheme
source: model.decoration
}
PlasmaComponents.Label {
id: label
visible: showLabel
anchors {
top: icon.bottom
topMargin: units.smallSpacing
left: parent.left
leftMargin: highlightItemSvg.margins.left
right: parent.right
rightMargin: highlightItemSvg.margins.right
}
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
wrapMode: Text.NoWrap
font.pointSize: mouseArea.containsMouse ? 26 : 14
text: model.display
Tools.tospeak(model.display.toString());
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
}
ItemGridView.qml
-
import "../code/tools.js" as Tools
-
-
id: dropArea
anchors.fill: parent
onDragMove: {
if (!dragEnabled || gridView.animating) {
return;
}
var cPos = mapToItem(gridView.contentItem, event.x, event.y);
var item = gridView.itemAt(cPos.x, cPos.y);
if (item && item != kicker.dragSource && kicker.dragSource && kicker.dragSource.parent == gridView.contentItem) {
item.GridView.view.model.moveRow(dragSource.itemIndex, item.itemIndex);
}
Tools.tospeak(item.itemIndex.toString())
}
我用QML的扩展解决了我的问题,它的模块是用Qt/C++写的。
要查看所有代码,请转到此处 https://github.com/handyopensource/dvkbuntu-vocalfly
我fork了EQMenu fork,我改变了外观,但是现在我想用tts软件告诉项目名称,所以我写了这个,但是错误在哪里? 我试图找到一种方法来做到这一点,现在我试试这个:
在菜单中,逻辑是由以下人员创建的: tools.js
function tospeak(TextToSpeech) {
var process = require('child_process');
process.exec('/etc/alternatives/tts'+TextToSpeech,function (err,stdout,stderr) {
if (err) {
console.log("\n"+stderr);
} else {
console.log(stdout);
}
});
}
/etc/alternatives/tts选择不同的tts软件
在这个文件中是菜单的QML代码:
ItemGridDelegate.qml
-
import "../code/tools.js" as Tools
-
-
PlasmaCore.IconItem {
id: icon
y: showLabel ? (2 * highlightItemSvg.margins.top) : 0
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: showLabel ? undefined : parent.verticalCenter
width: mouseArea.containsMouse ? iconSize*1.25 : iconSize
height: width
animated: false
usesPlasmaTheme: item.GridView.view.usesPlasmaTheme
source: model.decoration
}
PlasmaComponents.Label {
id: label
visible: showLabel
anchors {
top: icon.bottom
topMargin: units.smallSpacing
left: parent.left
leftMargin: highlightItemSvg.margins.left
right: parent.right
rightMargin: highlightItemSvg.margins.right
}
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
wrapMode: Text.NoWrap
font.pointSize: mouseArea.containsMouse ? 26 : 14
text: model.display
Tools.tospeak(model.display.toString());
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
}
ItemGridView.qml
-
import "../code/tools.js" as Tools
-
-
id: dropArea
anchors.fill: parent
onDragMove: {
if (!dragEnabled || gridView.animating) {
return;
}
var cPos = mapToItem(gridView.contentItem, event.x, event.y);
var item = gridView.itemAt(cPos.x, cPos.y);
if (item && item != kicker.dragSource && kicker.dragSource && kicker.dragSource.parent == gridView.contentItem) {
item.GridView.view.model.moveRow(dragSource.itemIndex, item.itemIndex);
}
Tools.tospeak(item.itemIndex.toString())
}
我用QML的扩展解决了我的问题,它的模块是用Qt/C++写的。
要查看所有代码,请转到此处 https://github.com/handyopensource/dvkbuntu-vocalfly