web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

如何利用CSS+jQuery做一个文字转语音机器人

397 ℃
     

如何利用CSS+jQuery做一个文字转语音机器人,下面web建站小编给大家详细介绍一下实现代码!

html代码

<div class="robot">
  <div class="tianxian"></div>
  <div class="gun"></div>
  <div class="gai"></div>
  <div class="head">
    <div class="erduo"></div>
    <div class="erduo"></div>
    <div class="face">
      <div class="eye"></div>
      <div class="eye"></div>
    </div>
  </div>
</div>
<div class="trans">
  <input id="input" type="text">
  <div id="btn">点击朗读</div>
</div>

css代码

* {
  margin: 0;
  padding: 0;
  list-style: none;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}
.robot{
  width: 658px;
  height:800px;
  position: absolute;
  left: 0;
  right: 0;
  margin: auto;
  top: 0;
  bottom: 0;
}
.tianxian{
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background: #0e58cc;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  margin: auto;
}
.tianxian::after{
  content: '';
  display: block;
  width: 5px;
  height: 10px;
  border-radius: 12px;
  background: #fff;
  position: absolute;
  top: 10px;
  left: 5px;
  transform: rotateZ(20deg);
}
.gun{
  width: 5px;
  height: 30px;
  background:#0075af ;
  position: absolute;
  left: 0;
  right: 0;
  top: 35px;
  margin: auto;
}
.gai{
  width: 60px;
  height: 60px;
  background: #fff;
  box-shadow: -5px -5px 30px 1px #0075af inset;
  position: absolute;
  left: 0;
  right: 0;
  top: 65px;
  margin: auto;
  border-radius: 50%;
}
.head{
  width: 370px;
  height: 350px;
  position: absolute;
  left: 0;
  right: 0;
  top: 95px;
  margin: auto;
  border-radius: 70px;
  background: #fff;
  box-shadow: -5px -5px 30px 1px #0075af inset;
}
.erduo{
  width: 60px;
  height: 180px;
  background: #0022b0;
  position: absolute;
  top: 0;
  bottom: 0;
  margin: auto 0;
  border-radius: 60px;
  border-top: 4px solid #0e9df9;
  border-bottom: 4px solid #0e9df9;
  box-shadow: -5px -5px 30px 1px #0075af inset;
}
.erduo:nth-child(1) {
  border-left: 4px solid #0e9df9;
  left: -40px;
}
.erduo:nth-child(2){
  border-right: 4px solid #0e9df9;
  right: -40px;
  box-shadow: -5px -5px 30px 1px #0075af inset;
}
.face{
  width: 288px;
  height: 244px;
  background: #03192f;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  border-radius: 60px;
  box-shadow: -5px -5px 30px 1px #0075af inset;
}
.eye{
  width: 30px;
  height: 100px;
  background-image: url('图片');
  background-size: contain;
  position: absolute;
  top: 0;
  bottom: 0;
  margin: auto;
}
.eye:nth-child(1){
  left: 60px;
}
.eye:nth-child(2){
  right: 60px;
}
.trans{
  width:370px;
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  left: 0;
  right: 0;
  margin: auto;
  top:  600px;
  font-size: 16px;
}
#input{
  margin-right: 10px;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  border-bottom: 1px dashed #fff;
  height: 40px;
}
#btn{
  cursor: pointer;
}
.shine {
  animation: shine 1s linear infinite;
}
@keyframes shine {
  0%{
    height: 100px;
  }
  100%{
    height: 0px;
  }
}

js代码

$(function () {
  $('#btn').click(function () {
    let text = $('#input').val()
    if (text) {
      $('.eye').addClass('shine')
    }
    let u = new window.SpeechSynthesisUtterance()
    u.text = text
    u.lang = 'zh'
    u.rate = 0.7
    u.onend = function () {
      $('.eye').removeClass('shine')
    }
    speechSynthesis.speak(u)
  })
})

简单介绍关于jquery的所有遍历方法

span点击事件后实现点击事件禁用(类似按钮disabeld方法)

如何利用css语法控制文本显示行数

css如何去掉滚动条占用的高度

利用css实现文本的单行溢出省略和多行溢出省略

标签: css, jquery, 文字转语音, 机器人

上面是“如何利用CSS+jQuery做一个文字转语音机器人”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2670.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计2664个字,预计阅读时长18分钟
生活小工具,收录了80多款小工具
上一篇: win7系统设置防火墙报0x8007042c错误解决方法
下一篇: 国家送给全国人民的9个免费神器(赶紧收藏)
x 打工人ai神器