js+css实现颜色声音识别代码
代码语言:html
所属分类:其他
代码描述:js+css实现颜色声音识别代码,主要通过SpeechRecognition
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <style> /* import font(s) */ @import url("https://fonts.googleapis.com/css?family=Open+Sans"); /* root variables */ :root { --font: "Open Sans", sans-serif; /* colors for the app */ --color-main: #f3eee6; --color-text: #010711; --color-bg: #031634; --color-highlight: #398a8711; /* colors for the parrot */ --color-head: #398a87; --color-beak: #ffd046; --color-beak-d: #d1a82b; /* color accent for the paragraph elements, modified according to a color potentially registered in the application */ --color-accent: #e03e0b; } * { box-sizing: border-box; margin: 0; padding: 0; } body { width: 100%; font-family: var(--font); color: var(--color-text); background: var(--color-bg); } /* ditance the main container notably from the top of the window, to give space to the parror + speech bubble */ main { max-width: 400px; width: 90vw; margin: 4rem auto; /* set a fixed height */ height: 80vh; background: var(--color-main); box-shadow: 0 1px 10px -1px var(--color-text); /* position relative to absolute position the parrot in relation to this container */ position: relative; } /* stretch the container nesting the text (and eventually the speech retrieved from the web speech api) to cover the entirety of the parent width and height */ .app__speech { width: 100%; height: 100%; padding: 1rem; border: 1rem inset var(--color-head); /* vertical overflow when the text forces the container past the prescribed 80vh height */ overflow-y: auto; } /* distance the paragraphs from one another and add the accent color */ .app__speech p { margin: 0.5rem 0; padding-left: 0.5rem; border-left: 0.25rem solid var(--color-accent); } /* show a simple placeholder value through a pseudo element, but only when the first paragraph in the container is empty (this is added immediately in the script) */ .app__speech p:nth-of-type(1):empty:before { content: "With your permission, I'll parrot whatever you are going to say in the microphone."; opacity: 0.85; line-height: 2; font-style: italic; } /* minor stylistic choices regarding the scrollbar */ .app__speech::-webkit-scrollbar { width: 0.35rem; } .app__speech::-webkit-scrollbar-track { box-shadow: inset 0 0 6px var(--color-beak); } .app__speech::-webkit-scrollbar-thumb { background: var(--color-beak-d); border-radius: 5px; } /* minor stylistic choices regarding the highlight */ .app__speech::selection { background: var(--color-beak); } .app__speech::-moz-selection { background: var(--color-beak); } /* absolute position the empty div making up the icon in the top left corner of the main container with a pseudo element for a small speech bubble*/ .app__parrot { width: 67px; height: 50px; position: absolute; top: 0; left: 0; transform: translate(-50%, -50%) rotate(-10deg); filter: drop-shadow(1px 1px 4px var(--color-highlight)); } .app__parrot:after { content: "Talk"; position: absolute; left: 95%; bottom: 80%; background: var(--color-main); padding: 0.5rem 0.8rem; border-radius: 20px 20px .........完整代码请登录后点击上方下载按钮下载查看
网友评论0