-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
126 lines (105 loc) · 3.81 KB
/
index.html
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
<html>
<head>
<title>Bayram Meets Automation</title>
<link href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap" rel="stylesheet">
<style>
.root {
display: flex;
flex-direction: row;
align-items: center;
}
.kutlayer-container {
width: 700px;
margin: auto;
}
.kutlayer-container>img {
width: 700px;
height: auto;
}
.kutlayer-container>audio {
margin: auto;
}
.subject-text {
position: relative;
bottom: 205px;
left: -50px;
font-family: 'Indie Flower', cursive;
color: #CEA4BA;
font-size: 40px;
text-transform: capitalize;
text-align: center;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
const urlParams = new URLSearchParams(window.location.search);
const name = urlParams.get('name');
let voiceText = urlParams.get('voice');
if (!voiceText) {
voiceText = name;
}
const imgSrc = urlParams.get('image');
if (imgSrc) {
document.getElementById('kutlama-img').src = imgSrc;
}
const textElement = document.querySelector(".subject-text");
textElement.innerHTML = name;
loadCustomVoice(voiceText);
document.querySelector("#audio-player").addEventListener('ended', function() {
const subjectVoiceController = document.querySelector("#subject-voice-controller");
subjectVoiceController.play();
});
});
function loadCustomVoice(voiceText) {
const reqBody = {
audioConfig: {
audioEncoding: "LINEAR16",
pitch: 0,
speakingRate: 1
},
input: {
text: voiceText,
},
voice: {
languageCode: "tr-TR",
name: "tr-TR-Wavenet-A"
}
};
fetch('https://texttospeech.googleapis.com/v1beta1/text:synthesize?key=AIzaSyAxA4bQg_XFe2OYrrO7_0Hdhm5D4jlEyG8',
{
method: 'POST', body: JSON.stringify(reqBody), headers: { 'content-type': 'application/json' }
})
.then(response => {
if (response.status === 200) {
return response.json();
} else {
throw new Error('Something went wrong on api server!');
}
})
.then(response => {
const subjectVoiceSource = document.querySelector("#subject-voice-source");
const subjectVoiceController = document.querySelector("#subject-voice-controller");
subjectVoiceSource.src = `data:audio/wav;base64,${response.audioContent}`;
subjectVoiceController.volume = 0.4;
subjectVoiceController.load();
}).catch(error => {
console.error(error);
});
}
</script>
</head>
<body>
<div class="root">
<div class="kutlayer-container">
<audio autoplay controls id="audio-player">
<source src="kutlayer_voice.mp3">
</audio>
<img src="kutlayer.jpg" id="kutlama-img" />
<div class="subject-text">Loading</div>
<audio autobuffer id="subject-voice-controller">
<source id="subject-voice-source" src="data:audio/wav;base64,">
</audio>
</div>
</div>
</body>
</html>