forked from daanzu/speech-training-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecorder.qml
166 lines (147 loc) · 4.7 KB
/
recorder.qml
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.3
import QtMultimedia 5.8
Window {
id: root
visible: true
width: 800; height: 400
color: "#aaa"
title: qsTr("Recorder")
property bool recording: false
property string promptsName: ''
property string scriptText: ''
property string scriptFilename: ''
property string saveDir: '.'
Component.onCompleted: initTimer.start()
Timer {
id: initTimer
interval: 0
onTriggered: recorder.init(scriptModel)
}
onRecordingChanged: recorder.toggleRecording(recording)
onScriptFilenameChanged: scriptModel.get(scriptListView.currentIndex).filename = scriptFilename
function appendScript(data) {
scriptModel.append(data)
}
function gotoNextScript() {
scriptListView.incrementCurrentIndex();
scriptListView.positionViewAtIndex(scriptListView.currentIndex, ListView.Center);
}
ListModel {
id: scriptModel
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 6
Frame {
Layout.fillHeight: true
Layout.fillWidth: true
focus: true
ListView {
id: scriptListView
model: scriptModel
anchors.fill: parent
focus: true
clip: true
ScrollBar.vertical: ScrollBar { active: true; policy: ScrollBar.AlwaysOn }
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
onCurrentItemChanged: {
scriptText = model.get(currentIndex).script;
scriptFilename = model.get(currentIndex).filename;
console.log('selected: "' + scriptText + '", ' + scriptFilename);
}
delegate: Item {
width: parent.width - 20
height: 30
Column {
Text {
text: script
font.pointSize: 10
}
Text {
text: 'Filename: ' + filename
font.pointSize: 8
}
}
MouseArea {
anchors.fill: parent
onClicked: scriptListView.currentIndex = index
}
}
}
}
CheckBox {
Layout.fillWidth: true
font.pointSize: 14
text: 'Filter all punctuation (only speak normal words!)'
checked: true
enabled: false
}
TextArea {
Layout.fillWidth: true
font.pointSize: 14
wrapMode: TextEdit.Wrap
readOnly: true
text: scriptText
background: Rectangle {
border.width: 3
border.color: recording ? "#2b2" : "#b22"
}
}
Button {
Layout.fillWidth: true
Layout.preferredHeight: 60
font.pointSize: 16
highlighted: recording
text: recording ? "Stop" : "Start"
onClicked: {
recording = !recording;
if (recording) {
recorder.startRecording();
} else {
recorder.finishRecording();
gotoNextScript();
}
}
}
RowLayout {
Button {
Layout.fillWidth: true
font.pointSize: 14
text: "Play"
enabled: scriptFilename
highlighted: playFile.playbackState == playFile.PlayingState
// onClicked: recorder.playFile(scriptFilename)
onClicked: {
playFile.source = scriptFilename
playFile.play()
}
Audio {
id: playFile
source: ''
}
}
Button {
Layout.fillWidth: true
font.pointSize: 14
text: "Delete"
enabled: scriptFilename
onClicked: recorder.deleteFile(scriptFilename)
}
Button {
Layout.fillWidth: true
font.pointSize: 14
text: recording ? "Cancel" : "Next"
onClicked: {
if (recording) {
recording = !recording;
} else {
gotoNextScript()
}
}
}
}
}
}