-
Notifications
You must be signed in to change notification settings - Fork 1
/
Episode 5.gs
70 lines (57 loc) · 1.88 KB
/
Episode 5.gs
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
function doGet() {
return HtmlService.createTemplateFromFile('textspeechconverter.html').evaluate();
}
function includeExternalFile(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
function speechToText(bytes) {
const base64 = Utilities.base64Encode(bytes);
const data = {
'config': {
'languageCode': 'en-US',
'audio_channel_count': 2,
},
'audio': {
'content': base64,
}
}
const params = {
'method' : 'post',
'headers': {
"Content-Type": "application/json",
},
'payload' : JSON.stringify(data),
};
const res = UrlFetchApp.fetch('https://speech.googleapis.com/v1/speech:recognize?key=AIzaSyBA6qflEf5lgVEyH55KXVDwiNP05W7aZjk', params);
return JSON.parse(res.getContentText())['results'][0]['alternatives'][0]['transcript'];
}
function textToSpeech(text) {
const data = {
"input": {
'text': text,
},
"voice": {
'languageCode': 'en-US',
'name': 'en-US-Standard-H',
},
"audioConfig": {
'audioEncoding': 'MP3',
}
}
const params = {
'method' : 'post',
'headers': {
"Content-Type": "application/json",
},
'payload' : JSON.stringify(data),
};
const res = UrlFetchApp.fetch('https://texttospeech.googleapis.com/v1/text:synthesize?key=AIzaSyBA6qflEf5lgVEyH55KXVDwiNP05W7aZjk', params);
return Utilities.base64Decode(JSON.parse(res.getContentText())['audioContent']);
}
function base64Demo() {
// Logger.log(Utilities.base64Encode('Base64 makes data transfer over the web so much easier!', Utilities.Charset.UTF_8));
Logger.log(Utilities.base64EncodeWebSafe('texts?_t=1a~'));
Logger.log(Utilities.base64Encode('texts?_t=1a~'));
Logger.log(Utilities.newBlob(Utilities.base64DecodeWebSafe('dGV4dHM_X3Q9MWF-')).getDataAsString());
Logger.log(Utilities.newBlob(Utilities.base64Decode('dGV4dHM/X3Q9MWF+')).getDataAsString());
}