diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2fc41c --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +### Example user template template +### Example user template + +# IntelliJ project files +.idea +*.iml +out +gen +.gradle +build \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..80184ab --- /dev/null +++ b/build.gradle @@ -0,0 +1,50 @@ +plugins { + id 'org.springframework.boot' version '2.5.2' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'java' + id "org.asciidoctor.jvm.convert" version "3.3.2" +} + +group = "org.example" +version = "1.0-SNAPSHOT" + +springBoot { + mainClass = 'org.example.Main' +} + +repositories { + mavenCentral() +} + +tasks.withType(JavaCompile){ + options.encoding = "UTF-8" +} +jar { + manifest { + attributes 'Main-Class': 'org.example.Main' + } +} + + + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.9.1")) + + implementation 'org.springframework:spring-web:6.0.0' + // json + implementation 'com.googlecode.json-simple:json-simple:1.1.1' + // stt + implementation 'com.google.cloud:google-cloud-speech:2.6.1' + // tts + implementation 'com.google.cloud:google-cloud-texttospeech:2.6.0' + implementation 'org.apache.httpcomponents:httpcore:4.4.16' + // mp3 + implementation 'javazoom:jlayer:1.0.1' + +} + + + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..ff17651 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Dec 06 20:48:09 KST 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..2a3f894 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the LiceWnse at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..ec856c9 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +W@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..7985be1 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'careheim' diff --git a/src/main/java/org/example/ClothData.java b/src/main/java/org/example/ClothData.java new file mode 100644 index 0000000..b853d6d --- /dev/null +++ b/src/main/java/org/example/ClothData.java @@ -0,0 +1,87 @@ +package org.example; + +import org.json.simple.JSONArray; + +public class ClothData{ + // 서버에서 전송한 데이터 저장할 변수 + static String success; + + static JSONArray statuses; + + //body +// static Long type; +// static Long pattern; // 패턴 +// +// static String cType; +// static String cPattern; +// +// static JSONArray colors; // 색 +// static JSONArray features; // 특징 : 추가 정보 +// +// static JSONArray careInfos; // 케어라벨 정보 +// static boolean hasStain; // 오염 여부 +// static boolean canDetectStain; // 오염 탐지 가능 여부 + + + public static String TYPE(int t) { +// int t = Integer.parseInt(type2); + String type = null; + + if(t==0) + type="반소매 상의"; + else if(t==1) + type="긴소매 상의"; + else if(t==2) + type="반소매 외투"; + else if(t==3) + type="긴소매 외투"; + else if(t==4) + type="조끼"; + else if(t==5) + type="민소매"; + else if(t==6) + type="반바지"; + else if(t==7) + type="긴바지"; + else if(t==8) + type="치마"; + else if(t==9) + type="반소매 원피스"; + else if(t==10) + type="긴소매 원피스"; + else if(t==11) + type="민소매 원피스"; + + return type; + } + + public static String PATTERN(int p) { + //int p = Integer.parseInt(a); + String pattern = null; + + if(p==0) + pattern="동물 얼룩 무늬"; + else if(p==1) + pattern="체크 무늬"; + else if(p==2) + pattern="지그재그 무늬"; + else if(p==3) + pattern="마름모 무늬"; + else if(p==4) + pattern="꽃무늬"; + else if(p==5) + pattern="그림이 그려져 있는 무늬"; + else if(p==6) + pattern="글씨가 쓰여 있는 무늬"; + else if(p==7) + pattern="민무늬"; + else if(p==8) + pattern="땡땡이 무늬"; + else if(p==9) + pattern="줄무늬"; + else if(p==10) + pattern="인식할 수 없는"; + + return pattern; + } +} \ No newline at end of file diff --git a/src/main/java/org/example/DataSend.java b/src/main/java/org/example/DataSend.java new file mode 100644 index 0000000..e474463 --- /dev/null +++ b/src/main/java/org/example/DataSend.java @@ -0,0 +1,242 @@ +package org.example; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.UUID; + +public class DataSend { + public static boolean isSuccess; + public static int code; + public static String message; + public static JSONArray result; + + public static int type; + public static int ptn; + public static JSONArray colors; + public static String color = ""; + public static JSONArray features; + public static String feature = ""; + + public static String nickName = ""; + /* "canDetectStain" : true, +"hasStain" : true or false, // only when 'canDetectStain' is true +"status" : 1, +"careInfos" : ["손세탁", "표백 금지"] // only when 'status' is true*/ + + public static String nickname; + public static boolean canDetectStain; + public static boolean hasStain; + public static int status; + public static JSONArray careInfos; + public static String careInfo = ""; + + public static void clothExtract(byte[] image) { + // 요청을 보낼 uri 작성 + String uri = "http://119.192.42.243:10002/clothes/extract"; + + // 응답을 주고 받을 template 생성 + RestTemplate restTemplate = new RestTemplate(); + + // Header 설정 + HttpHeaders headers = new HttpHeaders(); + + // Content-type 설정 + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + // RequestPart를 담을 map 생성 + MultiValueMap multipartBody = new LinkedMultiValueMap<>(); + + // image Part 추가 + multipartBody.add("image", new ByteArrayResource(image) { + @Override + public String getFilename() { + return String.valueOf(UUID.randomUUID()); // 이미지 파일명 설정 + } + }); + + // 요청 json object 생성 / 값 넣기 - json.simple lib 사 + JSONObject jsonObject = new JSONObject(); + jsonObject.put("Content-Type", "multipart"); + + // multipartBody에 json 추가 + multipartBody.add("form-data", jsonObject.toJSONString()); + + // HttpEntity 설정 + HttpEntity> entity = new HttpEntity<>(multipartBody, headers); + + try { + // Http 요청 - 응답을 String으로 받을 것 명시 + ResponseEntity response = restTemplate.postForEntity(uri, entity, String.class); + String resultGet = response.getBody(); // response의 body를 가져옴 + + System.out.println(resultGet); + + /* 의류 정보 등록_Get */ + JSONParser parser = new JSONParser(); + // JSON 파싱 + JSONObject getjsonObject = (JSONObject) parser.parse(resultGet); //** + + /* 의류 정보 등록_Get */ + isSuccess = (boolean) getjsonObject.get("isSuccess"); + code = ((Long) getjsonObject.get("code")).intValue(); + message = (String) getjsonObject.get("message"); + result = (JSONArray) getjsonObject.get("result"); + for(int i=0;i response = client.send(request, HttpResponse.BodyHandlers.ofString()); + String resultGet = response.body(); // response의 body를 가져옴 + + System.out.println("result :" + resultGet); + /* 의류 정보 등록_Get */ + JSONParser parser = new JSONParser(); + // JSON 파싱 + JSONObject obj = (JSONObject) parser.parse(resultGet); //** + /* 의류 정보 등록_Get */ + isSuccess = (boolean) obj.get("isSuccess"); + code = ((Long) obj.get("code")).intValue(); + message = (String) obj.get("message"); + + } catch (IOException | InterruptedException | ParseException e) { + e.printStackTrace(); + } + } + + // image? : 읽어 온 이미지 파일의 byte array + public static void ClothInfo(byte[] image) { + // 요청을 보낼 uri 작성 + String uri = "http://119.192.42.243:10002/clothes/careInfos"; + + // 응답을 주고 받을 template 생성 + RestTemplate restTemplate = new RestTemplate(); + + // Header 설정 + HttpHeaders headers = new HttpHeaders(); + + // Content-type 설정 + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + // RequestPart를 담을 map 생성 + MultiValueMap multipartBody = new LinkedMultiValueMap<>(); + + // image Part 추가 + multipartBody.add("image", new ByteArrayResource(image) { + @Override + public String getFilename() { + return String.valueOf(UUID.randomUUID()); // 이미지 파일명 설정 + } + }); + + // 요청 json object 생성 / 값 넣기 - json.simple lib 사 + JSONObject jsonObject = new JSONObject(); + jsonObject.put("Content-Type", "multipart"); + + // multipartBody에 json 추가 + multipartBody.add("form-data", jsonObject.toJSONString()); + + // HttpEntity 설정 + HttpEntity> entity = new HttpEntity<>(multipartBody, headers); + + try { + // Http 요청 - 응답을 String으로 받을 것 명시 + ResponseEntity response = restTemplate.postForEntity(uri, entity, String.class); + String resultGet = response.getBody(); // response의 body를 가져옴 + System.out.println("resultGet: "+resultGet); + + //String json = "{\"isSuccess\":true,\"code\":200,\"message\":\"요청에 성공하였습니다.\",\"result\":[{\"type\":1,\"ptn\":7,\"colors\":[\"연한 주황색\"],\"canDetectStain\":true,\"hasStain\":true,\"status\":1,\"careInfos\":[\"다림질 가능\",\"표백 불가능\",\"손세탁 가능\"]}]}"; + /* 의류 정보 등록_Get */ + JSONParser parser = new JSONParser(); + // JSON 파싱 + JSONObject getjsonObject = (JSONObject) parser.parse(resultGet); //** + System.out.println("getjsonObject: "+getjsonObject); + /* 의류 정보 등록_Get */ + isSuccess = (boolean) getjsonObject.get("isSuccess"); + code = ((Long) getjsonObject.get("code")).intValue(); + message = (String) getjsonObject.get("message"); + result = (JSONArray) getjsonObject.get("result"); + color = ""; + feature = ""; + for(int i=0;i listAllSupportedVoices() throws Exception { + // Instantiates a client + try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { + // Builds the text to speech list voices request + ListVoicesRequest request = ListVoicesRequest.getDefaultInstance(); + + // Performs the list voices request + ListVoicesResponse response = textToSpeechClient.listVoices(request); + List voices = response.getVoicesList(); + + for (Voice voice : voices) { + // Display the voice's name. Example: tpc-vocoded + System.out.format("Name: %s\n", voice.getName()); + + // Display the supported language codes for this voice. Example: "en-us" + List languageCodes = voice.getLanguageCodesList().asByteStringList(); + for (ByteString languageCode : languageCodes) { + System.out.format("Supported Language: %s\n", languageCode.toStringUtf8()); + } + + // Display the SSML Voice Gender + System.out.format("SSML Voice Gender: %s\n", voice.getSsmlGender()); + + // Display the natural sample rate hertz for this voice. Example: 24000 + System.out.format("Natural Sample Rate Hertz: %s\n\n", voice.getNaturalSampleRateHertz()); + } + return voices; + } + } + + + // img name + static File file; + public static File imgName(String baseFileName) { + //String baseFileName = "file"; + String fileExtension = ".mp3"; + + int fileNumber = 1; + + do { + String fileName = baseFileName + fileNumber + fileExtension; + file = new File(fileName); + fileNumber++; + } while (file.exists()); + + try { + // 파일 생성 및 처리 + boolean created = file.createNewFile(); + if (created) { + System.out.println("mp3파일이 생성되었습니다: " + file.getName()); + // 여기에서 파일에 대한 추가 작업을 수행할 수 있습니다. + } else { + System.out.println("mp3파일을 생성할 수 없습니다."); + } + } catch (IOException e) { + e.printStackTrace(); + } + return file; + } + + + public static String sen; + public static ResponseObserver responseObserver; + public static void sttTest() { + ResponseObserver responseObserver = null; + try (SpeechClient client = SpeechClient.create()) { + + responseObserver = new ResponseObserver() { + ArrayList responses = new ArrayList<>(); + + public void onStart(StreamController controller) { + } + + public void onResponse(StreamingRecognizeResponse response) { + responses.add(response); + } + + public void onComplete() { + String record = "tts\\outpu1.mp3"; + + for (StreamingRecognizeResponse response : responses) { + StreamingRecognitionResult result = response.getResultsList().get(0); + SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); + record += alternative.getTranscript(); + sen = alternative.getTranscript(); + System.out.printf("Transcript : %s\n", sen); + } + } + + public void onError(Throwable t) { + System.out.println(t); + } + }; + + ClientStream clientStream = client.streamingRecognizeCallable() + .splitCall(responseObserver); + + RecognitionConfig recognitionConfig = RecognitionConfig.newBuilder() + .setEncoding(RecognitionConfig.AudioEncoding.LINEAR16).setLanguageCode("ko-KR")// 한국어 설정 + .setSampleRateHertz(16000).build(); + StreamingRecognitionConfig streamingRecognitionConfig = StreamingRecognitionConfig.newBuilder() + .setConfig(recognitionConfig).build(); + + StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder() + .setStreamingConfig(streamingRecognitionConfig).build(); // The first request in a streaming call + // has to be a config + + clientStream.send(request); + // SampleRate:16000Hz, SampleSizeInBits: 16, Number of channels: 1, Signed: + // true, + // bigEndian: false + AudioFormat audioFormat = new AudioFormat(16000, 16, 1, true, false); + DataLine.Info targetInfo = new Info(TargetDataLine.class, audioFormat); // Set the system information to + // read from the microphone audio + // stream + + if (!AudioSystem.isLineSupported(targetInfo)) { + System.out.println("Microphone not supported"); + System.exit(0); + } + // Target data line captures the audio stream the microphone produces. + TargetDataLine targetDataLine = (TargetDataLine) AudioSystem.getLine(targetInfo); + targetDataLine.open(audioFormat); + targetDataLine.start(); + System.out.println("Start speaking"); + long startTime = System.currentTimeMillis(); + // Audio Input Stream + AudioInputStream audio = new AudioInputStream(targetDataLine); + while (true) { + long estimatedTime = System.currentTimeMillis() - startTime; + byte[] data = new byte[9000]; + audio.read(data); + if (estimatedTime > 6000) { // 60 seconds 스트리밍 하는 시간설정(기본 60초) + System.out.println("Stop speaking."); + targetDataLine.stop(); + targetDataLine.close(); + break; + } + request = StreamingRecognizeRequest.newBuilder().setAudioContent(ByteString.copyFrom(data)).build(); + clientStream.send(request); + } + } catch (Exception e) { + System.out.println(e); + } + responseObserver.onComplete(); //완료 이벤트 발생 + } +} \ No newline at end of file diff --git a/src/main/resources/credentials/stt1129-4cb24dd13a77.json b/src/main/resources/credentials/stt1129-4cb24dd13a77.json new file mode 100644 index 0000000..7e1583a --- /dev/null +++ b/src/main/resources/credentials/stt1129-4cb24dd13a77.json @@ -0,0 +1,13 @@ +{ + "type": "service_account", + "project_id": "stt1129", + "private_key_id": "4cb24dd13a774de51f4fd9f635cf5b65706aac59", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCdqYWWn4cuXiNr\nMFIeH7ExPNKimsOmolbIrvGuqzbZIqA9Hp12+iBJqH7oal7uwCTtdKeTyWTAFnBK\nV+XDZ9+2aTHk/6g1pqMEzBGbPyQAbSA2jbFln153W+5T3WZ7c33buyCVQAS4L6Qi\nnCsv2D1ty4ydMcweBWfmtnb0mnUGGNPVFs5mRMvnqOrBy7JcMVZXZ1YR+RQgIpRU\n4KrXVIHxjv0K76MKp32o6cJlvuXJVGzvpILIBvwONcDVYh64VDWSrtLC6yClfJtk\n7IZ9zUZ3FZ2bCqzw9TX5J93ToxRQ16qvKoj5PGNG5kdfDx2nVkpqwiLpIBLg9EHS\nl/Q7IYmHAgMBAAECggEAEgM9q3VDbQU9V7A4GY/2XxE7YW98HewbLSdrnlCaXhlq\nJEF8rQyrpq60/Rm2CeHy9hwnTyeptpZ5ssyzB+20rfL7y9V3otWMd25XLpz6oH/X\nN9RdaaZZFRrwMi2v2TfbL8ED2nlrcJ2ky317I6a5cfNY99aqIt3sPnwnQA/rgcwj\ncq//ueicEK2gVzAdbvdiH2oPiE3fjOTbvTv9ZAGaA8FLHqFsNuDVHDcAQSsQOx6+\nKkpAE4lRFX+1CwmCZ/8NueYgye65285cPYd1kyd3l/OKNGwxpBp2td0sF+5Nc4PP\nMJy3KEzCp5f/V9P67fw8yZDNuSCFGYjuGxBrFrz35QKBgQDLYzF9gd6lfqsTlr4A\nKct77IupIa0pp/TK+nlK9sYOssXz8WGeqPd378bhjNDFMe+BKcCaiWlS46OaJvep\ndGV9LngFirRU0og/eLVA1sT5Ng6gFPGc38G39efj0eFhopqijp0IjCtC1BeDnBUu\nggnkww2gRJJbrrtvXTr6vXm7EwKBgQDGckpv0gtgKjHKw3D2qQKlng1FOhl9eoqF\n8ZpHlchRCvE2pNg7hTFQPUcsIPDzktSpi5Thf9IJSBWTxjXkc7tgO7za/we9iAk7\nDXEredTWPYSrKR7smgb3OSerMdTvHkVrIL54VuoVPTEqpXEhQLad+SkShJyL5Gu+\nZ/FSNZjyPQKBgECr9uWosQpAn9dnvFzC7XAnRDVwfuZbAKy2PnFGzK2JzQYHf/n6\nUk4x0TSRGSVK/pQ8mYDKJtJzjecLcv7QAyFt8D4a38KE+0vrbv8CC7oOpVHjtvwh\n7jA3ohe/+gGYucDsxiQcpfjnBd8Ud2vFb63tE90dUMiUZAdCRunJ6/Y/AoGANb21\n0tp7IivLGDIdYW8bvGY1Cc5WINkSsntfYIt7mBbyg+3YcSX82NH/eD/jgNL+rHuU\ncgz/gGv5C+/doGSHFeSXnGb8XaN9fHSDdValAO/gAco9Ca4cvM7Jo173X1o/Smev\nrT88XUwZCIeNP4ga7GURbmZjTq8pToMvoyfIp7ECgYEAukPtn7amolXp6JqoTsjy\nf3YO2z9GTgM5J+uf1IPWfBsZ+7EOlsM/9WBRWaVQFbXexAwadZCC7QEsFA4VmnWL\nPpX/3uG0A/v2IaS8CgaI7oAdjay1Ps08dcbW2jRRbN1UnH2BcJ33hwmTBejqjbw9\n19kl4F/cOxayMKFzC2lFDLM=\n-----END PRIVATE KEY-----\n", + "client_email": "tts1129@stt1129.iam.gserviceaccount.com", + "client_id": "105635947727626688159", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/tts1129%40stt1129.iam.gserviceaccount.com", + "universe_domain": "googleapis.com" +} diff --git a/src/main/resources/credentials/stt1129-75a8e4476560.json b/src/main/resources/credentials/stt1129-75a8e4476560.json new file mode 100644 index 0000000..f4ebbd6 --- /dev/null +++ b/src/main/resources/credentials/stt1129-75a8e4476560.json @@ -0,0 +1,13 @@ +{ + "type": "service_account", + "project_id": "stt1129", + "private_key_id": "75a8e44765602db1038e4492796846d093f8e0c9", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCcbn6Q/BT1brj6\nTDkppCCvOOnlW8+Zin8vobfqSHOfMfb+Ic3bd8TdAt68n4fatuGO8n23zWjb0QG6\nR1SnN3UxA10O227SH4tG1fHo1nI3lgsOCPV3E9UaaywjnS3rggWXbRZjbm9WKjHU\nsR9IM2rVYj6IeE2V/6/WprHmCR+RdSPMRLiNCJPXMmUBFyOUYtvblSyfCEAvMUmE\nsrQuw+2A30OFN1OFxlFCi1T3aHi0ilioThBXuN4zYQ8Iv1Db/uuNPeVQwBUph7Vn\nTtdkZFM0yqfUYHRrC5ZZmovE4egwLmmWDY7E0bFyIAV0lXd+Z1bTNwnKRKGC2zUt\nHnFVqUXfAgMBAAECggEABeGhoJHZt+CR09dJzub805mwMY9iHsO2RHQwFf7jWfjm\n8GcU9ktqe2TAOxdEZFS75kP3thFi/+C7z+UeqarMHSujNAvL/tpwwhkJH1fws2ZQ\nxBZSJEf6myOsZSpjr5cT3r2bOeHNDdBIT1bZdj14ps0qzLa5NAqI8ekShzOQnEdc\nIyIDkvXGIPHjk7b2JdtKnbkkmDH81jIR/jj7fu8cNeBkInCj/OX1OIUGBIqh1H8C\nMa9dnGoaALHDPOJCGLMBTIPFIjP/JQ79VQzwFrDXch7qcD/gihO1oAAAA81KYbup\ns/aUuBrBDTrf7avnzNsh/G4rXnVdJBMd/HjighXuAQKBgQDOX0ljUEaocL+sWLRQ\nyfj7zvOQf+N36RPck0HXCS1o9lSx6Tzxw7WHu53YIwBxRdvp6yuYbk4oVq+HLCYk\nuVqGx+KB0XFm8Dkq7XPM+kap3N3ebh6HOx3aTTMrk3S78H2VeNCor2myVt+3KhxN\nWJVZPd08MMzyG2LRr8z5o8C8CQKBgQDCDMId3Qh0rRh8Oz06L6qoQW9/uQ6mLUse\nyGeK3qr4Yv+N/Y9TDX/xlNMKzAbzkypprgL1BomgytkErXtbNGXZLzhO7bxBOym4\nmgkNXLhz10OV9CWVtiL12ElzvwFPQmMsQceiEHlUt+8lgcNmvnNbjQXgPEzr7hfC\nSRJnmBi8pwKBgCKlCHLttQ7t7p+GPK8bWPsc4PKvJYap0DXFWtY4qjDmuY0sdJi5\nnC3vJy5zoc1iRurcGfN7AQ/wjYMJvFWJ8FKUF8hnWrxHM7GrLzeIBHjbpTuEDQfy\nuq49K4vzMzOhydNf9td6qynPP7tGDH5Hkrrqkcta/ezfABXnh2eZP+/RAoGADPsN\ngTHn/uYVXToZPmsx30+BRen7MOKWw9hkFMYQac01iyoLDGM6y85Iz9AWJvURQUCC\nsiFd04O+QLHaLp+ysHSYL693iGWMxOyI7nvlWtprivxqBznH3Oo6/6MnU0X9nFhK\nIm03sJMdTEUB7T2QOe+VFQrzmlSzAiwhLwzdmsECgYEAx/vAipQ8yRp8JqM9Pdow\nk1MGSW9ouWkay11K5sjZUMqERNs9uBuvmLx1FxkbdQ46kivNDHHoMGtiNWInlAiF\ndrnuVYjgoztFnU7uLlWILd8d96Sczc6iejSbeNJzy/ITpYlVO67VOy/6+LYA7g8k\n/D7Pq8ZnmqqTTVI8mOXrMI0=\n-----END PRIVATE KEY-----\n", + "client_email": "stt1129@stt1129.iam.gserviceaccount.com", + "client_id": "107190595683765596549", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/stt1129%40stt1129.iam.gserviceaccount.com", + "universe_domain": "googleapis.com" +} diff --git a/src/main/resources/img/test.jpg b/src/main/resources/img/test.jpg new file mode 100644 index 0000000..754b5a1 Binary files /dev/null and b/src/main/resources/img/test.jpg differ diff --git a/src/main/resources/img/test1.jpg b/src/main/resources/img/test1.jpg new file mode 100644 index 0000000..9568c68 Binary files /dev/null and b/src/main/resources/img/test1.jpg differ diff --git a/src/main/resources/mp3/0.mp3 b/src/main/resources/mp3/0.mp3 new file mode 100644 index 0000000..2b41776 Binary files /dev/null and b/src/main/resources/mp3/0.mp3 differ diff --git a/src/main/resources/mp3/careHeim_start_0.mp3 b/src/main/resources/mp3/careHeim_start_0.mp3 new file mode 100644 index 0000000..75d7bc5 Binary files /dev/null and b/src/main/resources/mp3/careHeim_start_0.mp3 differ diff --git a/src/main/resources/mp3/careHeim_start_1.mp3 b/src/main/resources/mp3/careHeim_start_1.mp3 new file mode 100644 index 0000000..367e0eb Binary files /dev/null and b/src/main/resources/mp3/careHeim_start_1.mp3 differ diff --git a/src/main/resources/mp3/change.mp3 b/src/main/resources/mp3/change.mp3 new file mode 100644 index 0000000..41cdc12 Binary files /dev/null and b/src/main/resources/mp3/change.mp3 differ diff --git a/src/main/resources/mp3/enroll text 0.mp3 b/src/main/resources/mp3/enroll text 0.mp3 new file mode 100644 index 0000000..2fa531d Binary files /dev/null and b/src/main/resources/mp3/enroll text 0.mp3 differ diff --git a/src/main/resources/mp3/enroll_0.mp3 b/src/main/resources/mp3/enroll_0.mp3 new file mode 100644 index 0000000..3a8f32b Binary files /dev/null and b/src/main/resources/mp3/enroll_0.mp3 differ diff --git a/src/main/resources/mp3/enroll_end.mp3 b/src/main/resources/mp3/enroll_end.mp3 new file mode 100644 index 0000000..a9963fc Binary files /dev/null and b/src/main/resources/mp3/enroll_end.mp3 differ diff --git a/src/main/resources/mp3/exit.mp3 b/src/main/resources/mp3/exit.mp3 new file mode 100644 index 0000000..059ad6a Binary files /dev/null and b/src/main/resources/mp3/exit.mp3 differ diff --git a/src/main/resources/mp3/exit_mp31.mp3 b/src/main/resources/mp3/exit_mp31.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/mp3/info2.mp3 b/src/main/resources/mp3/info2.mp3 new file mode 100644 index 0000000..6abd51d Binary files /dev/null and b/src/main/resources/mp3/info2.mp3 differ diff --git a/src/main/resources/mp3/info5.mp3 b/src/main/resources/mp3/info5.mp3 new file mode 100644 index 0000000..a3f9997 Binary files /dev/null and b/src/main/resources/mp3/info5.mp3 differ diff --git a/src/main/resources/mp3/info6.mp3 b/src/main/resources/mp3/info6.mp3 new file mode 100644 index 0000000..29d4626 Binary files /dev/null and b/src/main/resources/mp3/info6.mp3 differ diff --git a/src/main/resources/mp3/info7.mp3 b/src/main/resources/mp3/info7.mp3 new file mode 100644 index 0000000..88bc403 Binary files /dev/null and b/src/main/resources/mp3/info7.mp3 differ diff --git a/src/main/resources/mp3/infoC.mp3 b/src/main/resources/mp3/infoC.mp3 new file mode 100644 index 0000000..6fe43ff Binary files /dev/null and b/src/main/resources/mp3/infoC.mp3 differ diff --git a/src/main/resources/mp3/infoC_mp31.mp3 b/src/main/resources/mp3/infoC_mp31.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/mp3/info_0.mp3 b/src/main/resources/mp3/info_0.mp3 new file mode 100644 index 0000000..cfbfb79 Binary files /dev/null and b/src/main/resources/mp3/info_0.mp3 differ diff --git a/src/main/resources/mp3/info_care.mp3 b/src/main/resources/mp3/info_care.mp3 new file mode 100644 index 0000000..f4872b8 Binary files /dev/null and b/src/main/resources/mp3/info_care.mp3 differ diff --git a/src/main/resources/mp3/info_care_mp31.mp3 b/src/main/resources/mp3/info_care_mp31.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/mp3/info_end.mp3 b/src/main/resources/mp3/info_end.mp3 new file mode 100644 index 0000000..7c47194 Binary files /dev/null and b/src/main/resources/mp3/info_end.mp3 differ diff --git a/src/main/resources/mp3/info_no_stain.mp3 b/src/main/resources/mp3/info_no_stain.mp3 new file mode 100644 index 0000000..e2ed15e Binary files /dev/null and b/src/main/resources/mp3/info_no_stain.mp3 differ diff --git a/src/main/resources/mp3/info_not_enroll.mp3 b/src/main/resources/mp3/info_not_enroll.mp3 new file mode 100644 index 0000000..096ddac Binary files /dev/null and b/src/main/resources/mp3/info_not_enroll.mp3 differ diff --git a/src/main/resources/mp3/info_num.mp3 b/src/main/resources/mp3/info_num.mp3 new file mode 100644 index 0000000..c31442c Binary files /dev/null and b/src/main/resources/mp3/info_num.mp3 differ diff --git a/src/main/resources/mp3/info_num.mp31.mp3 b/src/main/resources/mp3/info_num.mp31.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/mp3/info_stain.mp3 b/src/main/resources/mp3/info_stain.mp3 new file mode 100644 index 0000000..897551b Binary files /dev/null and b/src/main/resources/mp3/info_stain.mp3 differ diff --git a/src/main/resources/mp3/info_text_0.mp3 b/src/main/resources/mp3/info_text_0.mp3 new file mode 100644 index 0000000..f37f31a Binary files /dev/null and b/src/main/resources/mp3/info_text_0.mp3 differ diff --git a/src/main/resources/mp3/info_text_1.mp3 b/src/main/resources/mp3/info_text_1.mp3 new file mode 100644 index 0000000..2256352 Binary files /dev/null and b/src/main/resources/mp3/info_text_1.mp3 differ diff --git a/src/main/resources/mp3/info_text_2.mp3 b/src/main/resources/mp3/info_text_2.mp3 new file mode 100644 index 0000000..cce827f Binary files /dev/null and b/src/main/resources/mp3/info_text_2.mp3 differ diff --git a/src/main/resources/mp3/noUser.mp3 b/src/main/resources/mp3/noUser.mp3 new file mode 100644 index 0000000..68e5f40 Binary files /dev/null and b/src/main/resources/mp3/noUser.mp3 differ diff --git a/src/main/resources/mp3/photo1.mp3 b/src/main/resources/mp3/photo1.mp3 new file mode 100644 index 0000000..da32dfa Binary files /dev/null and b/src/main/resources/mp3/photo1.mp3 differ diff --git a/src/main/resources/mp3/photo321.mp3 b/src/main/resources/mp3/photo321.mp3 new file mode 100644 index 0000000..5ca19db Binary files /dev/null and b/src/main/resources/mp3/photo321.mp3 differ diff --git a/src/main/resources/mp3/photo_321.mp3 b/src/main/resources/mp3/photo_321.mp3 new file mode 100644 index 0000000..9e03c40 Binary files /dev/null and b/src/main/resources/mp3/photo_321.mp3 differ diff --git a/src/main/resources/mp3/photo_warn.mp3 b/src/main/resources/mp3/photo_warn.mp3 new file mode 100644 index 0000000..e40f1fb Binary files /dev/null and b/src/main/resources/mp3/photo_warn.mp3 differ diff --git a/src/main/resources/mp3/start0.mp3 b/src/main/resources/mp3/start0.mp3 new file mode 100644 index 0000000..bc3235d Binary files /dev/null and b/src/main/resources/mp3/start0.mp3 differ