From 466b2180af19c96d9da8e25245d78f8bf66da2ce Mon Sep 17 00:00:00 2001 From: JHyunB Date: Sat, 10 Oct 2020 01:23:53 +0900 Subject: [PATCH 1/2] Add ignore resources --- .gitignore | 1 + src/main/kotlin/com/whiskey/client/AzureAiClient.kt | 11 ----------- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 src/main/kotlin/com/whiskey/client/AzureAiClient.kt diff --git a/.gitignore b/.gitignore index 1fbae6c..2d6fc97 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ out .DS_Store **/*.kotlintest +src/main/resources/ \ No newline at end of file diff --git a/src/main/kotlin/com/whiskey/client/AzureAiClient.kt b/src/main/kotlin/com/whiskey/client/AzureAiClient.kt deleted file mode 100644 index c4dd03d..0000000 --- a/src/main/kotlin/com/whiskey/client/AzureAiClient.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.whiskey.client - -import org.springframework.stereotype.Component - -/** - * 1. Make a connection to azure ai api - * 2. Make a rest api client for stt, keyword extraction - */ -@Component -class AzureAiClient { -} \ No newline at end of file From 558f05968580e0660db1fb221af204d0881b28e4 Mon Sep 17 00:00:00 2001 From: JHyunB Date: Sat, 10 Oct 2020 01:24:29 +0900 Subject: [PATCH 2/2] Azure STT basic code --- .../com/whiskey/provider/AzureSTTProvider.kt | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/whiskey/provider/AzureSTTProvider.kt b/src/main/kotlin/com/whiskey/provider/AzureSTTProvider.kt index 09399d7..f547121 100644 --- a/src/main/kotlin/com/whiskey/provider/AzureSTTProvider.kt +++ b/src/main/kotlin/com/whiskey/provider/AzureSTTProvider.kt @@ -1,12 +1,42 @@ package com.whiskey.provider -import com.whiskey.client.AzureAiClient +import com.microsoft.cognitiveservices.speech.* +import com.microsoft.cognitiveservices.speech.audio.AudioConfig import org.springframework.stereotype.Service +import java.util.concurrent.Future + /** * Make a STT result provider */ @Service -class AzureSTTProvider( - private val azureAiClient: AzureAiClient -) \ No newline at end of file +class AzureSTTProvider +{ + val SPEECH__SUBSCRIPTION__KEY = System.getenv("SPEECH__SUBSCRIPTION__KEY") + val SPEECH__SERVICE__REGION = System.getenv("SPEECH__SERVICE__REGION") + fun main(){ + // setting + val config: SpeechConfig = SpeechConfig.fromSubscription(SPEECH__SUBSCRIPTION__KEY, SPEECH__SERVICE__REGION) + val audioConfig = AudioConfig.fromWavFileInput("file") + val recognizer = SpeechRecognizer(config,"en-US", audioConfig) + val task: Future = recognizer.recognizeOnceAsync() + val result: SpeechRecognitionResult = task.get() + + + when (result.reason) { + ResultReason.RecognizedSpeech -> { + println("We recognized: " + result.text) + } + ResultReason.NoMatch -> println("NOMATCH: Speech could not be recognized.") + ResultReason.Canceled -> { + val cancellation = CancellationDetails.fromResult(result) + println("CANCELED: Reason=" + cancellation.reason) + if (cancellation.reason == CancellationReason.Error) { + println("CANCELED: ErrorCode=" + cancellation.errorCode) + println("CANCELED: ErrorDetails=" + cancellation.errorDetails) + println("CANCELED: Did you update the subscription info?") + } + } + } + } +} \ No newline at end of file