Warning, /libraries/libqmycroft/lib/qml/TranscribeButton.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.12
0002 import QtQuick.Controls 2.12 as Controls
0003 import Libqmycroft 1.0
0004 
0005 Controls.Button {
0006     id: rootControl
0007     property bool transcribeActive: false
0008     property var target: parent
0009     anchors.right: parent.right
0010     icon.name: "audio-input-microphone"
0011     icon.width: parent.width / 2
0012     icon.height: parent.height / 2
0013     icon.color: activePalette.mid
0014     property var requestID
0015 
0016     function generateUniqueID(){
0017         audTranscriber.generateRequestIdentifier()
0018         requestID = audTranscriber.getRequestIdentifier()
0019     }
0020 
0021     Component.onCompleted: {
0022         generateUniqueID()
0023     }
0024 
0025     onTranscribeActiveChanged: {
0026         if(!transcribeActive){
0027             audTranscriber.stop()
0028         }
0029     }
0030 
0031     background: Rectangle {
0032         color: "transparent"
0033     }
0034 
0035     SystemPalette {
0036         id: activePalette
0037         colorGroup: SystemPalette.Active
0038     }
0039 
0040     AudioTranscribe {
0041         id: audTranscriber
0042 
0043         onResponseReceived: {
0044             try {
0045                 rootControl.target.text = response
0046             }
0047             catch(error) {
0048                 console.log(error)
0049             }
0050         }
0051     }
0052 
0053     Timer {
0054         id: timer
0055     }
0056 
0057     function delay(delayTime, cb) {
0058         timer.interval = delayTime;
0059         timer.repeat = false;
0060         timer.triggered.connect(cb);
0061         timer.start();
0062     }
0063 
0064     Keys.onReturnPressed: {
0065         clicked()
0066     }
0067 
0068     onClicked: {
0069         if(audTranscriber.status == AudioTranscribe.Inactive){
0070             if(!rootControl.transcribeActive) {
0071                 audTranscriber.start()
0072                 rootControl.transcribeActive = true
0073                 icon.color = activePalette.highlight
0074                 delay(8000, function() {
0075                     rootControl.transcribeActive = false
0076                     icon.color = activePalette.mid
0077                 })
0078             }
0079         }
0080     }
0081 }