-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathvue-init.js
180 lines (169 loc) · 5.75 KB
/
vue-init.js
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var app = new Vue({
el: '#speechToText',
data: {
finishTime: '',
i18n: i18n,
filename: 'SpeechToText',
//loadFromURLValue: 'chi.ogg',
//loadFromURLValue: 'https://www.youtube.com/watch?v=GE7sc_XvJ8w',
loadFromURLValue: '',
customLang: '',
//extAudio: ['3gp','aa','aac','aax','act','aiff','amr','ape','au','awb','dct','dss','dvf','flac','gsm','iklax','ivs','m4a','m4b','m4p','mmf','mp3','mpc','msv','nsf','ogg, oga, mogg','opus','ra, rm','raw','sln','tta','vox','wav','wma','wv','webm','8svx'],
// https://developer.mozilla.org/zh-TW/docs/Web/HTML/Supported_media_formats
extAudio: ['wav', 'ogg', 'mp3'],
extVedio: ['mp4'],
playerTemplate: {
video: `<video controls class="audio-player" style="display: block;max-width: 320px;max-height: 180px;">
<source src="{{URL}}" type="video/mp4">
Your browser does not support the audio element.
</video>`,
audio: `<div class="ui icon message">
<i class="file audio outline icon"></i>
{{FILENAME}}
</div>
<audio controls class="audio-player">
<source src="{{URL}}" type="{{MIME_TYPE}}">
Your browser does not support the audio element.
</audio>`
}
//loadFromURLValue: ''
},
methods: {
checkLoadFromURL: function () {
var _this = this
$(function () {
setTimeout(function () {
if ($('.setting-load-from-url').val() !== '') {
_this.loadFromURLValue = $('.setting-load-from-url').val()
}
if (_this.loadFromURLValue !== '') {
_this.loadFromURL()
}
else {
_this.loadDemoVideo()
}
}, 500)
})
},
loadFromURL: function (event) {
$('.recognition-status').attr('data-recognition-status', 'loading')
//console.log(this.loadFromURLValue)
var type = this.detectURLtype(this.loadFromURLValue)
//console.log(type)
var playerContainer = $('#audio_player')
if (type === 'youtube') {
var _this = this
this.loadFromURLYouTube(this.loadFromURLValue, playerContainer, function () {
$('.recognition-status').attr('data-recognition-status', 'ready')
_this.reset()
//console.log('aaaa')
})
}
else if (type === 'video') {
this.loadFromURLVideo(this.loadFromURLValue, playerContainer)
$('.recognition-status').attr('data-recognition-status', 'ready')
this.reset()
}
else if (type === 'audio') {
this.loadFromURLAudio(this.loadFromURLValue, playerContainer)
$('.recognition-status').attr('data-recognition-status', 'ready')
this.reset()
}
},
changeLang: function (lang) {
$('.lang').val(lang);
$('#customLang').val('');
},
setFilename: function (filename) {
// https://stackoverflow.com/a/3780731
if (!filename) {
filename = 'unknown'
}
filename = filename.replace(/[|&;$%@"<>()+,]/g, "");
if (filename.length > 15) {
filename = filename.slice(0, 15)
}
this.filename = filename
},
loadFromURLYouTube: function (url, playerContainer, callback) {
var videoId = YouTubeUtils.validateYouTubeUrl(url)
//console.log(videoId)
playerContainer.html('<div id="audio_player_youtube"></div>')
var _this = this
YouTubeUtils.setPlayer('audio_player_youtube', videoId, function () {
_this.setFilename(YouTubeUtils.getTitle())
if (typeof(callback) === "function") {
setTimeout(function () {
callback()
}, 100)
}
})
},
loadFromURLVideo: function (url, playerContainer) {
var template = this.playerTemplate.video
template = template.split('{{URL}}').join(url)
playerContainer.html(template)
this.setFilename(getFilenameFromURL(url))
},
loadFromURLAudio: function (url, playerContainer) {
var template = this.playerTemplate.audio
template = template.split('{{URL}}').join(url)
var ext = getExtFromURL(url)
var mime = ext
if (mime === 'mp3') {
mime = 'mpeg'
}
mime = 'audio/' + mime
template = template.split('{{MIME_TYPE}}').join(mime)
var filename = getFullFilenameFromURL(url)
template = template.split('{{FILENAME}}').join(filename)
playerContainer.html(template)
this.setFilename(getFilenameFromURL(url))
},
detectURLtype: function (url) {
if (YouTubeUtils.validateYouTubeUrl(url) !== false) {
return 'youtube'
}
else {
var ext = getExtFromURL(url)
//console.log(ext)
//console.log(ext.indexOf(this.extAudio))
//console.log(this.extAudio.indexOf(ext))
if (this.extAudio.indexOf(ext) > -1) {
return 'audio'
}
else {
return 'video'
}
}
},
reset: function () {
SpeechToText.reset()
setTimeout(function () {
$('[data-persist="garlic"] input').change()
}, 100)
},
confirmReset: function () {
if (SpeechToText.hasContent()) {
return window.confirm(i18n.t('Text will be reset. Are you sure?'))
}
},
grantMicrophonePermission: function () {
VoiceAccess.grantMicrophonePermission()
},
openVirtualAudioCableHelpModel: function () {
$('.ui.modal.virtual-audio-cable-help-modal').modal('show')
},
loadDemoVideo: function () {
var playerContainer = $('#audio_player')
this.loadFromURLVideo('chi.mp4', playerContainer)
this.setFilename('SpeechToText')
this.clearLoadFromURLValue()
this.reset()
},
clearLoadFromURLValue: function () {
this.loadFromURLValue = ''
}
}
})
app.checkLoadFromURL()