├── .classpath ├── .gitignore ├── .launch ├── mrcp4j - clean.launch ├── mrcp4j - jar.launch ├── mrcp4j - publish.launch └── mrcp4j - publishToMavenLocal.launch ├── .project ├── .settings ├── org.eclipse.buildship.core.prefs ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── .travis.yml ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── bin └── .gitignore ├── build.gradle ├── codeql-analysis.yml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── settings ├── assembly │ ├── bin.xml │ └── src.xml └── eclipse │ └── codetemplates.xml └── src ├── main ├── java │ └── org │ │ └── mrcp4j │ │ ├── MrcpEventName.java │ │ ├── MrcpException.java │ │ ├── MrcpMethodName.java │ │ ├── MrcpRequestState.java │ │ ├── MrcpResourceType.java │ │ ├── client │ │ ├── MrcpChannel.java │ │ ├── MrcpEventDecoder.java │ │ ├── MrcpEventListener.java │ │ ├── MrcpFactory.java │ │ ├── MrcpInvocationException.java │ │ ├── MrcpMessageDecoder.java │ │ ├── MrcpMessageHandler.java │ │ ├── MrcpProvider.java │ │ ├── MrcpRequestEncoder.java │ │ ├── MrcpResponseDecoder.java │ │ ├── MrcpSocket.java │ │ └── package.html │ │ ├── message │ │ ├── MrcpEvent.java │ │ ├── MrcpMessage.java │ │ ├── MrcpMessageFactory.java │ │ ├── MrcpResponse.java │ │ ├── MrcpServerMessage.java │ │ ├── header │ │ │ ├── BaseValueFactory.java │ │ │ ├── ChannelIdentifier.java │ │ │ ├── CompletionCause.java │ │ │ ├── GenericValueFactory.java │ │ │ ├── IllegalValueException.java │ │ │ ├── MrcpHeader.java │ │ │ ├── MrcpHeaderName.java │ │ │ ├── RequestIdList.java │ │ │ ├── ValueFactory.java │ │ │ ├── VendorSpecificHeader.java │ │ │ └── package.html │ │ ├── package.html │ │ └── request │ │ │ ├── MrcpRequest.java │ │ │ ├── MrcpRequestFactory.java │ │ │ ├── RecordRequest.java │ │ │ ├── StartInputTimersRequest.java │ │ │ ├── StopRequest.java │ │ │ └── package.html │ │ ├── package.html │ │ ├── server │ │ ├── MrcpCodecFactory.java │ │ ├── MrcpMessageEncoder.java │ │ ├── MrcpProtocolHandler.java │ │ ├── MrcpRequestDecoder.java │ │ ├── MrcpRequestHandler.java │ │ ├── MrcpRequestProcessor.java │ │ ├── MrcpRequestProcessorImpl.java │ │ ├── MrcpServerSocket.java │ │ ├── MrcpSession.java │ │ ├── delegator │ │ │ ├── GenericRequestDelegator.java │ │ │ ├── RecogOnlyRequestDelegator.java │ │ │ ├── RecorderRequestDelegator.java │ │ │ ├── SpeakVerifyRequestDelegator.java │ │ │ ├── SpeechSynthRequestDelegator.java │ │ │ ├── VoiceEnrollmentRequestDelegator.java │ │ │ └── package.html │ │ ├── mina │ │ │ ├── IoTextLoggingFilter.java │ │ │ ├── SimpleProtocolProvider.java │ │ │ └── package.html │ │ ├── package.html │ │ └── provider │ │ │ ├── GenericRequestHandler.java │ │ │ ├── RecogOnlyRequestHandler.java │ │ │ ├── RecorderRequestHandler.java │ │ │ ├── SpeakVerifyRequestHandler.java │ │ │ ├── SpeechSynthRequestHandler.java │ │ │ ├── VoiceEnrollmentRequestHandler.java │ │ │ └── package.html │ │ └── util │ │ ├── ObjectWrapper.java │ │ ├── ThrowingQueue.java │ │ └── package.html └── resources │ └── LICENSE.txt ├── site ├── apt │ ├── changelog.apt │ ├── doc.apt │ ├── index.apt │ ├── install.apt │ └── intro.apt ├── fml │ └── faq.fml ├── resources │ └── images │ │ ├── mrcp4j-banner.jpg │ │ └── speechforge-banner.jpg └── site.xml └── test ├── java └── org │ └── mrcp4j │ └── test │ └── MrcpClientServerTest.java └── resources └── log4j2.xml /.classpath: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.gradle/ 3 | /build/ 4 | -------------------------------------------------------------------------------- /.launch/mrcp4j - clean.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.launch/mrcp4j - jar.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.launch/mrcp4j - publish.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.launch/mrcp4j - publishToMavenLocal.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.mrcp4j 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | connection.project.dir= 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | install: true 3 | dist: trusty 4 | 5 | jdk: 6 | - oraclejdk8 7 | 8 | before_install: 9 | - sudo apt-get update 10 | - chmod +x gradlew 11 | 12 | script: 13 | - ./gradlew jar -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MRCP4j 2 | 3 | The MRCPv2 protocol is designed to allow client devices to control media 4 | processing resources, such as speech recognition engines. MRCP4J provides a 5 | Java API that encapsulates the MRCPv2 protocol and can be used to implement 6 | MRCP clients and/or servers. 7 | 8 | ## Requirements 9 | 10 | - JAVA 8 11 | - Gradle 7.3.1 12 | 13 | ## Include from from Maven 14 | 15 | Configure maven to use Central from your Project Object Model (POM) file.You may do so by 16 | adding the following to your pom.xml: 17 | 18 | 19 | 20 | central 21 | Maven Central 22 | default 23 | https://repo1.maven.org/maven2 24 | 25 | false 26 | 27 | 28 | 29 | 30 | Add mrcp4j as a dependecy to your pom.xml 31 | 32 | 33 | org.jvoicexml 34 | org.mrcp4j 35 | 0.3 36 | module 37 | 38 | 39 | ## Include from Gradle 40 | 41 | Add the Maven Central repository to your build.gradle 42 | 43 | repositories { 44 | mavenCentral() 45 | } 46 | 47 | Add mrcp4j as a an implementation dependency to your build.gradle 48 | 49 | implementation 'org.jvoicexml:org.mrcp4j:0.3' 50 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | /main/ 2 | /test/ 3 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'maven-publish' 4 | id 'signing' 5 | } 6 | 7 | repositories { 8 | mavenLocal() 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | api group: 'directory-network', name: 'mina', version: '0.8.0' 14 | api group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.2' 15 | api group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.2' 16 | api group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.17.2' 17 | 18 | testImplementation group: 'junit', name: 'junit', version: '4.13.2' 19 | } 20 | 21 | jar { 22 | manifest { 23 | attributes("Implementation-Title": 'MRCPv2 library for Java', 24 | 'Implementation-Vendor': 'switch', 25 | 'Implementation-Version': version, 26 | 'Built-By' : System.properties['user.name'], 27 | 'Build-Timestamp': new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()), 28 | 'Created-By' : "Gradle ${gradle.gradleVersion}", 29 | 'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})", 30 | 'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}") 31 | } 32 | baseName 'org.mrcp4j' 33 | } 34 | 35 | java { 36 | withJavadocJar() 37 | withSourcesJar() 38 | } 39 | 40 | publishing { 41 | publications { 42 | mavenJava(MavenPublication) { 43 | artifactId = tasks.jar.baseName 44 | from components.java 45 | versionMapping { 46 | usage('java-api') { 47 | fromResolutionOf('runtimeClasspath') 48 | } 49 | usage('java-runtime') { 50 | fromResolutionResult() 51 | } 52 | } 53 | pom { 54 | name = 'MRCP4j' 55 | description = 'MRCP4J provides a Java API that encapsulates the MRCPv2 protocol and can be used to implement MRCP clients and/or servers.' 56 | url = 'https://github.com/JVoiceXML/mrcp4j' 57 | licenses { 58 | license { 59 | name = 'GNU Lesser General Public License, Version 2.1' 60 | url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt' 61 | } 62 | } 63 | developers { 64 | developer { 65 | id = 'schnelle' 66 | name = 'Dirk Schnelle-Walka' 67 | email = 'dirk.schnelle@jvoicexml.org' 68 | } 69 | } 70 | scm { 71 | connection = 'scm:git@github.com:JVoiceXML/mrcp4j.git' 72 | developerConnection = 'scm:git@github.com:JVoiceXML/mrcp4j.git' 73 | url = "https://github.com/JVoiceXML/mrcp4j" 74 | } 75 | } 76 | } 77 | } 78 | repositories { 79 | maven { 80 | def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 81 | def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/" 82 | url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl 83 | credentials { 84 | username = JVOICEXML_OSSRH_USERNAME 85 | password = JVOICEXML_OSSRH_PASSWORD 86 | } 87 | } 88 | } 89 | } 90 | 91 | signing { 92 | sign publishing.publications.mavenJava 93 | } 94 | 95 | javadoc { 96 | if(JavaVersion.current().isJava9Compatible()) { 97 | options.addBooleanOption('html5', true) 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '18 6 * * 3' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v2 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v1 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v1 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v1 71 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=0.3 2 | JVOICEXML_GROUP = org.jvoicexml 3 | group = org.jvoicexml 4 | 5 | # Sonatype credentials 6 | JVOICEXML_OSSRH_USERNAME=MUST-BE-SUPPLIED-VALUE 7 | JVOICEXML_OSSRH_PASSWORD=MUST-BE-SUPPLIED-VALUE 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JVoiceXML/mrcp4j/90426ebb0cd1a495888324f964710947f66b43e6/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'org.mrcp4j' -------------------------------------------------------------------------------- /settings/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 2 | bin 3 | 4 | tar.gz 5 | tar.bz2 6 | zip 7 | 8 | true 9 | 10 | 11 | target/site/docs 12 | docs 13 | 14 | **/* 15 | 16 | 17 | apidocs/files 18 | apidocs/options 19 | 20 | 21 | 22 | 23 | 24 | target/${pom.artifactId}-${pom.version}.jar 25 | 26 | 27 | README.txt 28 | true 29 | 30 | 31 | LICENSE.txt 32 | 33 | 34 | NOTICE.txt 35 | 36 | 37 | 38 | 39 | /lib 40 | runtime 41 | 42 | commons-logging:commons-logging 43 | directory-network:mina 44 | org.slf4j:slf4j-simple 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /settings/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 2 | src 3 | 4 | tar.gz 5 | tar.bz2 6 | zip 7 | 8 | true 9 | 10 | 11 | src/main 12 | src 13 | 14 | java/**/*.* 15 | 16 | 17 | 18 | target/site/docs 19 | docs 20 | 21 | **/* 22 | 23 | 24 | apidocs/files 25 | apidocs/options 26 | 27 | 28 | 29 | 30 | 31 | pom.xml 32 | 33 | 34 | README.txt 35 | true 36 | 37 | 38 | LICENSE.txt 39 | 40 | 41 | NOTICE.txt 42 | 43 | 44 | -------------------------------------------------------------------------------- /settings/eclipse/codetemplates.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/MrcpEventName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j; 24 | 25 | /** 26 | * Defines the event names that are valid values for MRCPv2 event messages. 27 | * 28 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 29 | * @see org.mrcp4j.server.MrcpSession#createEvent(org.mrcp4j.MrcpEventName, org.mrcp4j.MrcpRequestState) 30 | */ 31 | public enum MrcpEventName { 32 | 33 | /* 34 | synthesizer-event = "SPEECH-MARKER" ; H 35 | / "SPEAK-COMPLETE" ; I 36 | */ 37 | /** 38 | * This event from the synthesizer resource to the client is generated when the synthesizer 39 | * encounters a marker tag in the speech markup it is currently processing. 40 | */ 41 | SPEECH_MARKER ("SPEECH-MARKER"), 42 | 43 | /** 44 | * This event from the synthesizer resource to the client indicates that the 45 | * corresponding "SPEAK" request was completed. 46 | */ 47 | SPEAK_COMPLETE ("SPEAK-COMPLETE"), 48 | 49 | /* 50 | recognizer-event = "START-OF-INPUT" ; L 51 | / "RECOGNITION-COMPLETE" ; M 52 | / "INTERPRETATION-COMPLETE" ; N 53 | */ 54 | /** 55 | * This event from the recognition resource, the recorder resource or the verification 56 | * resource to the client indicates speech or DTMF has been detected by the resource. 57 | */ 58 | START_OF_INPUT ("START-OF-INPUT"), 59 | 60 | /** 61 | * This event from the recognizer resource to the client indicates that recognition has completed. 62 | */ 63 | RECOGNITION_COMPLETE ("RECOGNITION-COMPLETE"), 64 | 65 | /** 66 | * This event from the recognition resource to the client indicates that the INTERPRET operation is complete. 67 | */ 68 | INTERPRETATION_COMPLETE ("INTERPRETATION-COMPLETE"), 69 | 70 | /* 71 | recorder-event = "START-OF-INPUT" ; D 72 | / "RECORD-COMPLETE" ; E 73 | */ 74 | //START_OF_INPUT ("START-OF-INPUT"), <- already defined under recognizer-event 75 | /** 76 | * This event from the recorder resource to the client indicates that recording has completed due either to 77 | * no-input, silence after speech or max-time exceeded. 78 | */ 79 | RECORD_COMPLETE ("RECORD-COMPLETE"), 80 | 81 | /* 82 | verification-event = "VERIFICATION-COMPLETE" ; L 83 | / "START-OF-INPUT" ; M 84 | */ 85 | /** 86 | * This event from the verification resource to the client follows a call to VERIFY or VERIFY-FROM-BUFFER 87 | * and is used to communicate the verification results to the client. 88 | */ 89 | VERIFICATION_COMPLETE ("VERIFICATION-COMPLETE"); 90 | //START_OF_INPUT ("START-OF-INPUT"), <- already defined under recognizer-event 91 | 92 | 93 | private String _name; 94 | 95 | private MrcpEventName(String name) { 96 | _name = name; 97 | } 98 | 99 | /* (non-Javadoc) 100 | * @see java.lang.Object#toString() 101 | */ 102 | @Override 103 | public String toString() { 104 | return _name; 105 | } 106 | 107 | /** 108 | * Converts an MRCP event name in string format to the appropriate MRCP4J enum value. 109 | * @param str MRCP event string 110 | * @return the event name enum instance corresponding to the string name specified 111 | * @throws IllegalArgumentException if the string value specified does not correspond to 112 | * a valid MRCP event name 113 | */ 114 | public static MrcpEventName fromString(String str) throws IllegalArgumentException { 115 | for (MrcpEventName value : MrcpEventName.values()) { 116 | if (value.toString().equalsIgnoreCase(str)) { 117 | return value; 118 | } 119 | } 120 | throw new IllegalArgumentException("Invalid MRCP event-name: " + str); 121 | } 122 | 123 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/MrcpException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j; 24 | 25 | /** 26 | * Base class for all MRCP4J exception types. 27 | * 28 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 29 | */ 30 | @SuppressWarnings("serial") 31 | public class MrcpException extends Exception { 32 | 33 | /** 34 | * 35 | */ 36 | public MrcpException() { 37 | super(); 38 | } 39 | 40 | /** 41 | * @param message the error message 42 | */ 43 | public MrcpException(String message) { 44 | super(message); 45 | } 46 | 47 | /** 48 | * @param message the error message 49 | * @param cause the root cause for this exception 50 | */ 51 | public MrcpException(String message, Throwable cause) { 52 | super(message, cause); 53 | } 54 | 55 | /** 56 | * @param cause the root cause for this exception 57 | */ 58 | public MrcpException(Throwable cause) { 59 | super(cause); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/MrcpRequestState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j; 24 | 25 | /** 26 | * Defines the request states that are valid for MRCPv2. 27 | * 28 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 29 | * @see org.mrcp4j.server.MrcpSession#createResponse(short, org.mrcp4j.MrcpRequestState) 30 | * @see org.mrcp4j.server.MrcpSession#createEvent(org.mrcp4j.MrcpEventName, org.mrcp4j.MrcpRequestState) 31 | */ 32 | public enum MrcpRequestState { 33 | 34 | /** 35 | * The request has been placed on a queue and will be processed in first-in-first-out order. 36 | */ 37 | PENDING ("PENDING"), 38 | 39 | /** 40 | * The request is being processed and is not yet complete. 41 | */ 42 | IN_PROGRESS ("IN-PROGRESS"), 43 | 44 | /** 45 | * The request has been processed to completion and there will be no more events or other 46 | * messages from the resource to the client with this request-id. 47 | */ 48 | COMPLETE ("COMPLETE"); 49 | 50 | private String _name; 51 | 52 | MrcpRequestState(String name) { 53 | _name = name; 54 | } 55 | 56 | /* (non-Javadoc) 57 | * @see java.lang.Object#toString() 58 | */ 59 | @Override 60 | public String toString() { 61 | return _name; 62 | } 63 | 64 | /** 65 | * Converts an MRCP request state in string format to the appropriate MRCP4J enum value. 66 | * @param str MRCP request state 67 | * @return the request state enum instance corresponding to the string value specified 68 | * @throws IllegalArgumentException if the string value specified does not correspond to 69 | * an existing MRCP request state 70 | */ 71 | public static MrcpRequestState fromString(String str) throws IllegalArgumentException { 72 | for (MrcpRequestState value : MrcpRequestState.values()) { 73 | if (value.toString().equalsIgnoreCase(str)) { 74 | return value; 75 | } 76 | } 77 | throw new IllegalArgumentException("Invalid MRCP request-state: " + str); 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/MrcpResourceType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j; 24 | 25 | /** 26 | * Defines the resource types that are valid for MRCPv2. 27 | * 28 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 29 | */ 30 | public enum MrcpResourceType { 31 | 32 | /** 33 | * A full speech recognition resource that is capable of receiving a media stream 34 | * containing audio and interpreting it to recognition results. 35 | */ 36 | SPEECHRECOG ("speechrecog"), 37 | 38 | /** 39 | * A recognition resource capable of extracting and interpreting DTMF digits in 40 | * a media stream and matching them against a supplied digit grammar. 41 | */ 42 | DTMFRECOG ("dtmfrecog"), 43 | 44 | /** 45 | * A full capability speech synthesis resource capable of rendering speech from text. 46 | */ 47 | SPEECHSYNTH ("speechsynth"), 48 | 49 | /** 50 | * A speech synthesizer resource with very limited capabilities that can generate its 51 | * media stream exclusively from concatenated audio clips. 52 | */ 53 | BASICSYNTH ("basicsynth"), 54 | 55 | /** 56 | * A resource capable of verifying the authenticity of a claimed identity by matching a 57 | * media stream containing a voice to a pre-existing voice-print. 58 | */ 59 | SPEAKVERIFY ("speakverify"), 60 | 61 | /** 62 | * A resource capable of recording audio and saving it to a URI. 63 | */ 64 | RECORDER ("recorder"); 65 | 66 | 67 | private String _name; 68 | 69 | MrcpResourceType(String name) { 70 | _name = name; 71 | } 72 | 73 | /* (non-Javadoc) 74 | * @see java.lang.Object#toString() 75 | */ 76 | @Override 77 | public String toString() { 78 | return _name; 79 | } 80 | 81 | /** 82 | * Converts an MRCP resource type in string format to the appropriate MRCP4J enum value. 83 | * @param str MRCP resource type. 84 | * @return the resource type enum instance corresponding to the string value specified. 85 | * @throws IllegalArgumentException if the string value specified does not correspond to 86 | * an existing MRCP resource type. 87 | */ 88 | public static MrcpResourceType fromString(String str) throws IllegalArgumentException { 89 | for (MrcpResourceType value : MrcpResourceType.values()) { 90 | if (value.toString().equalsIgnoreCase(str)) { 91 | return value; 92 | } 93 | } 94 | throw new IllegalArgumentException("Invalid MRCP resource type: " + str); 95 | } 96 | 97 | /** 98 | * Parses an MRCP channel ID to extract the resource type of the channel as the appropriate MRCP4J enum value. 99 | * @param channelID ID of the channel for which the resource type needs to be determined. 100 | * @return the resource type enum instance corresponding to the string value contained in the specified channel ID. 101 | * @throws IllegalArgumentException if the channel ID is not correctly formatted. 102 | */ 103 | public static MrcpResourceType fromChannelID(String channelID) { 104 | String[] tokens = channelID.split("@"); 105 | if (tokens.length != 2) { 106 | throw new IllegalArgumentException("Illegal Channel-Identifier value: " + channelID); 107 | } 108 | return fromString(tokens[1]); 109 | } 110 | 111 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpEventDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import org.mrcp4j.MrcpEventName; 26 | import org.mrcp4j.MrcpRequestState; 27 | import org.mrcp4j.message.MrcpEvent; 28 | 29 | import java.io.IOException; 30 | import java.text.ParseException; 31 | 32 | /** 33 | * Decodes event messages received in MRCPv2 format into {@link org.mrcp4j.message.MrcpEvent} instances. 34 | * 35 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 36 | */ 37 | public class MrcpEventDecoder { 38 | 39 | private static final int EVENT_LINE_MRCP_VERSION_PART = 0; 40 | private static final int EVENT_LINE_MESSAGE_LENGTH_PART = 1; 41 | private static final int EVENT_LINE_EVENT_NAME_PART = 2; 42 | private static final int EVENT_LINE_REQUEST_ID_PART = 3; 43 | private static final int EVENT_LINE_REQUEST_STATE_PART = 4; 44 | private static final int EVENT_LINE_PART_COUNT = 5; 45 | 46 | public MrcpEvent createEvent(String eventLine) throws IOException, ParseException { 47 | 48 | if (eventLine == null || (eventLine = eventLine.trim()).length() < 1) { 49 | throw new ParseException("No event-line provided!", -1); 50 | } 51 | 52 | String[] eventLineParts = eventLine.split(" "); 53 | if (eventLineParts.length != EVENT_LINE_PART_COUNT) { 54 | throw new ParseException("Incorrect event-line format!", -1); 55 | } 56 | 57 | MrcpEvent event = new MrcpEvent(); 58 | 59 | // mrcp-version 60 | event.setVersion(eventLineParts[EVENT_LINE_MRCP_VERSION_PART]); //TODO: check if this matches request version, maybe at a higher level... 61 | 62 | // message-length 63 | try { 64 | event.setMessageLength( 65 | Integer.parseInt(eventLineParts[EVENT_LINE_MESSAGE_LENGTH_PART]) 66 | ); 67 | } catch (NumberFormatException e){ 68 | String message = "Incorrect message-length format!"; 69 | throw (ParseException) new ParseException(message, -1).initCause(e); 70 | } 71 | 72 | // event-name 73 | try { 74 | event.setEventName( 75 | MrcpEventName.fromString(eventLineParts[EVENT_LINE_EVENT_NAME_PART]) 76 | ); 77 | } catch (IllegalArgumentException e){ 78 | String message = "Incorrect event-name format!"; 79 | throw (ParseException) new ParseException(message, -1).initCause(e); 80 | } 81 | 82 | // request-id 83 | try { 84 | event.setRequestID( 85 | Long.parseLong(eventLineParts[EVENT_LINE_REQUEST_ID_PART]) 86 | ); 87 | } catch (NumberFormatException e){ 88 | String message = "Incorrect request-id format!"; 89 | throw (ParseException) new ParseException(message, -1).initCause(e); 90 | } 91 | 92 | // request-state 93 | try { 94 | event.setRequestState( 95 | MrcpRequestState.fromString(eventLineParts[EVENT_LINE_REQUEST_STATE_PART]) 96 | ); 97 | } catch (IllegalArgumentException e){ 98 | String message = "Incorrect request-state format!"; 99 | throw (ParseException) new ParseException(message, -1).initCause(e); 100 | } 101 | 102 | return event; 103 | } 104 | 105 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import org.mrcp4j.message.MrcpEvent; 26 | 27 | /** 28 | * The listener interface for receiving MRCPv2 event messages. This interface should be 29 | * implemented by any class intended to be notified of any MRCP events received from 30 | * an MRCP resource by an {@link org.mrcp4j.client.MrcpChannel} instance. 31 | * 32 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 33 | * @see org.mrcp4j.client.MrcpChannel#addEventListener(org.mrcp4j.client.MrcpEventListener) 34 | * @see org.mrcp4j.client.MrcpChannel#removeEventListener(org.mrcp4j.client.MrcpEventListener) 35 | */ 36 | public interface MrcpEventListener { 37 | 38 | /** 39 | * Called when an MRCP event is received from a MRCP resource. 40 | * @param event the event received from the MRCP resource 41 | */ 42 | public void eventReceived(MrcpEvent event); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | /** 26 | * Provides factory methods for MRCPv2 clients to gain access to {@link org.mrcp4j.client.MrcpProvider} instances. 27 | *

28 | * Currently having to go through a factory to construct an MrcpProvider may seem like a bit of overkill. However, 29 | * this is implemented this way in order to facilitate transitioning in the future to a design in which there may 30 | * be multiple provider implementations accessible through a single factory method. 31 | *

32 | * 33 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 34 | */ 35 | public class MrcpFactory { 36 | 37 | private MrcpFactory() { 38 | // restrict instance initialization to private access 39 | } 40 | 41 | /** 42 | * Constructs a new {@code MrcpProvider} instance which provides client access to MRCP resources. 43 | * @return new provider instance. 44 | */ 45 | public MrcpProvider createProvider() { 46 | return new MrcpProvider(); 47 | } 48 | 49 | /** 50 | * Constructs a new {@code MrcpFactory} instance. 51 | * @return new factory instance. 52 | */ 53 | public static MrcpFactory newInstance() { 54 | return new MrcpFactory(); 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpInvocationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import org.mrcp4j.MrcpException; 26 | import org.mrcp4j.message.MrcpResponse; 27 | 28 | /** 29 | * Thrown when an exception is encountered while invoking an MRCPv2 request. For example when 30 | * an MRCP response returned by an MRCP resource contains an error code. 31 | * 32 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 33 | */ 34 | @SuppressWarnings("serial") 35 | public class MrcpInvocationException extends MrcpException { 36 | 37 | private final MrcpResponse _response; 38 | 39 | /** 40 | * @param response the response that triggered the exception to be thrown 41 | */ 42 | public MrcpInvocationException(MrcpResponse response) { 43 | //TODO: set response message text as the exception message 44 | super("MRCPv2 Status Code:" + response.getStatusCode() + "[" + response.getStatusDesc() + "]"); 45 | _response = response; 46 | } 47 | 48 | /** 49 | * Retrieves the response that triggered the exception to be thrown. 50 | * @return the response that triggered the exception to be thrown. 51 | */ 52 | public MrcpResponse getResponse() { 53 | return _response; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpMessageDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import java.io.BufferedReader; 26 | import java.io.IOException; 27 | import java.text.ParseException; 28 | 29 | import org.apache.log4j.LogManager; 30 | import org.apache.log4j.Logger; 31 | import org.mrcp4j.message.MrcpMessage; 32 | import org.mrcp4j.message.header.IllegalValueException; 33 | import org.mrcp4j.message.header.MrcpHeader; 34 | import org.mrcp4j.message.header.MrcpHeaderName; 35 | 36 | /** 37 | * Decodes messages received in MRCPv2 format into {@link org.mrcp4j.message.MrcpMessage} instances. 38 | * 39 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 40 | */ 41 | public class MrcpMessageDecoder { 42 | 43 | private static Logger _log = LogManager.getLogger(MrcpMessageDecoder.class); 44 | 45 | private MrcpResponseDecoder _responseDecoder = new MrcpResponseDecoder(); 46 | private MrcpEventDecoder _eventDecoder = new MrcpEventDecoder(); 47 | 48 | 49 | private static final int RESPONSE_LINE_REQUEST_ID_PART = 2; 50 | private static final int START_LINE_PART_COUNT = 5; 51 | 52 | // TODO: change ParseException to MrcpProtocolException 53 | public MrcpMessage decode(BufferedReader in) throws IOException, ParseException { 54 | 55 | // read until the first non-empty line to get the start-line 56 | String line = null; 57 | while ((line = in.readLine()) == null || (line = line.trim()).equals("")) { 58 | if (_log.isTraceEnabled()) 59 | _log.trace((line == null) ? "MrcpMessageDecoder: null line" : "MrcpMessageDecoder: empty line"); 60 | try { 61 | Thread.sleep(100); // TODO: make sleep time configurable 62 | } catch (InterruptedException e) { 63 | _log.debug(e, e); 64 | } 65 | } 66 | 67 | // verify the start-line contains the correct number of parts 68 | String[] startLineParts = line.split(" "); 69 | if (startLineParts.length != START_LINE_PART_COUNT) { 70 | throw new ParseException("Incorrect start-line format!", -1); 71 | } 72 | 73 | // determine if the message is a response or an event message 74 | boolean isResponse = false; 75 | try { 76 | Long.parseLong(startLineParts[RESPONSE_LINE_REQUEST_ID_PART]); 77 | isResponse = true; 78 | } catch (NumberFormatException e){ 79 | // ignore, message should be event 80 | } 81 | 82 | // create the message from the start-line 83 | MrcpMessage message = null; 84 | if (isResponse) { 85 | message = _responseDecoder.createResponse(line); 86 | } else { 87 | message = _eventDecoder.createEvent(line); 88 | } 89 | 90 | // populate message headers 91 | while ((line = in.readLine()) != null && !(line = line.trim()).equals("")) { 92 | // TODO: handle multi-line headers 93 | int index = line.indexOf(':'); 94 | if (index < 1) { 95 | throw new ParseException("Incorrect message-header format!", -1); 96 | } 97 | String name = line.substring(0, index); 98 | String value = line.substring(index + 1).trim(); 99 | MrcpHeader header = MrcpHeaderName.createHeader(name, value); 100 | message.addHeader(header); 101 | } 102 | 103 | // read message content if present 104 | MrcpHeader contentLengthHeader = message.getHeader(MrcpHeaderName.CONTENT_LENGTH); 105 | int contentLength = 0; 106 | try { 107 | contentLength = (contentLengthHeader == null) ? 0 : ((Integer) contentLengthHeader.getValueObject()).intValue(); 108 | } catch (IllegalValueException e) { 109 | throw new ParseException(e.getMessage(), -1); 110 | } 111 | if (contentLength > 0) { 112 | char[] content = new char[contentLength]; 113 | int length = in.read(content, 0, contentLength); 114 | if (length != contentLength) { 115 | throw new ParseException("Content length mismatch, expected " + 116 | contentLength + ", got " + length, -1); 117 | } 118 | message.setContent(new String(content)); 119 | } 120 | 121 | return message; 122 | } 123 | 124 | 125 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import org.mrcp4j.message.MrcpMessage; 26 | 27 | /** 28 | * The listener interface for processing MRCPv2 messages (for internal library use only). 29 | * 30 | *

This interface is intended for internal use by the MRCP4J implementation code. It should 31 | * not be implemented by MRCP clients interested in registering to be notified of MRCP events. 32 | * For that purpose please see {@link org.mrcp4j.client.MrcpEventListener} instead.

33 | * 34 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 35 | */ 36 | public interface MrcpMessageHandler { 37 | 38 | /** 39 | * Called when an MRCP message is received from an MRCP resource. 40 | * @param message the message received from the MRCP resource 41 | */ 42 | public void handleMessage(MrcpMessage message); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import org.mrcp4j.message.header.IllegalValueException; 26 | 27 | import java.io.IOException; 28 | import java.net.InetAddress; 29 | import java.util.HashMap; 30 | import java.util.Map; 31 | 32 | /** 33 | * Provides functionality for simplified management of {@link org.mrcp4j.client.MrcpChannel} instances by an MRCPv2 client. 34 | * 35 | *

To construct a {@code MrcpProvider} instance use {@link org.mrcp4j.client.MrcpFactory#createProvider()}.

36 | * 37 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 38 | */ 39 | public class MrcpProvider { 40 | 41 | /** 42 | * Transport protocol string for MRCPv2 over TCP. 43 | */ 44 | public static final String PROTOCOL_TCP_MRCPv2 = "TCP/MRCPv2"; 45 | 46 | /** 47 | * Transport protocol string for MRCPv2 over TLS over TCP (not yet supported in current version of MRCP4J). 48 | */ 49 | public static final String PROTOCOL_TLS_MRCPv2 = "TCP/TLS/MRCPv2"; 50 | 51 | /** 52 | * Compile time flag for setting whether to share {@link org.mrcp4j.client.MrcpSocket} instances. 53 | */ 54 | private static final boolean SHARE_SOCKETS = true; 55 | 56 | private Map _sockets = SHARE_SOCKETS ? new HashMap() : null; 57 | 58 | MrcpProvider() { 59 | // restrict constructor to package visibility 60 | } 61 | 62 | /** 63 | * Constructs a new MRCP channel and initiates an active connection with the specified MRCP resource. 64 | * @param channelID the channel ID for the channel being created. This ID should be discovered 65 | * during the resource allocation phase which is mediated using SIP messages 66 | * between the client and server. 67 | * @param host the location of the MRCP resource being accessed by the channel. 68 | * @param port the port at which the MRCP resource is listening for MRCP messages. 69 | * @param protocol the transport protocol being used to carry the MRCP messages (currently the only 70 | * supported value is {@link org.mrcp4j.client.MrcpProvider#PROTOCOL_TCP_MRCPv2}). 71 | * 72 | * @return an active MRCP channel connected to the host and port specified 73 | * @throws IOException if an I/O error occurs. 74 | * @throws IllegalArgumentException if an unsupported protocol value is passed. 75 | * @throws IllegalValueException if the channelID is not a valid value. 76 | */ 77 | public MrcpChannel createChannel(String channelID, InetAddress host, int port, String protocol) 78 | throws IOException, IllegalArgumentException, IllegalValueException { 79 | 80 | // currently only TCP/MRCPv2 is supported 81 | // TODO: add support for TCP/TLS/MRCPv2 82 | if (!PROTOCOL_TCP_MRCPv2.equalsIgnoreCase(protocol)) { 83 | throw new IllegalArgumentException("Unsupported protocol: " + protocol); 84 | } 85 | 86 | MrcpSocket socket = getSocket(host, port, "tcp"); 87 | MrcpChannel channel = new MrcpChannel(channelID, socket); 88 | return channel; 89 | // TODO: provide method to close channel 90 | } 91 | 92 | private MrcpSocket getSocket(InetAddress host, int port, String transport) 93 | throws IOException { 94 | if (!SHARE_SOCKETS) { 95 | return new MrcpSocket(host, port); 96 | } 97 | 98 | String key = getSocketKey(host, port, transport); 99 | 100 | synchronized (_sockets) { 101 | MrcpSocket socket = _sockets.get(key); 102 | if (socket == null) { 103 | //TODO: move socket initialization outside synchronization block 104 | socket = new MrcpSocket(host, port); 105 | _sockets.put(key, socket); 106 | } 107 | return socket; 108 | } 109 | } 110 | 111 | private static String getSocketKey(InetAddress host, int port, String transport) { 112 | StringBuilder key = new StringBuilder(host.getHostAddress()); 113 | key.append(':').append(port); 114 | key.append('/').append(transport.toLowerCase()); 115 | return key.toString(); 116 | } 117 | 118 | 119 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpRequestEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import static org.mrcp4j.message.MrcpMessage.CRLF; 26 | 27 | import org.mrcp4j.message.header.MrcpHeader; 28 | import org.mrcp4j.message.request.MrcpRequest; 29 | 30 | import java.io.IOException; 31 | import java.io.PrintWriter; 32 | 33 | /** 34 | * Encodes {@link org.mrcp4j.message.request.MrcpRequest} instances into MRCPv2 specification format. 35 | * 36 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 37 | */ 38 | public class MrcpRequestEncoder { 39 | 40 | public void encode(MrcpRequest request, PrintWriter out) throws IOException { 41 | 42 | StringBuilder messageBuffer = new StringBuilder(); 43 | 44 | // append request line 45 | int offset = appendResponseLine(messageBuffer, request); 46 | 47 | // append headers 48 | for (MrcpHeader header : request.getHeaders()) { 49 | messageBuffer.append(header.toString()).append(CRLF); 50 | } 51 | 52 | // append CRLF line 53 | messageBuffer.append(CRLF); 54 | 55 | // append message content if present 56 | if (request.hasContent()) { 57 | messageBuffer.append(request.getContent()); 58 | } 59 | 60 | // determine and set message length 61 | int bufferLength = messageBuffer.length(); 62 | int bufferLengthLength = Integer.toString(bufferLength).length(); 63 | int messageLength = bufferLength + bufferLengthLength; 64 | String messageLengthString = Integer.toString(messageLength); 65 | if (messageLengthString.length() > bufferLengthLength) { 66 | messageLengthString = Integer.toString(++messageLength); 67 | } 68 | messageBuffer.insert(offset, messageLengthString); 69 | request.setMessageLength(messageLength); 70 | bufferLength = messageBuffer.length(); 71 | 72 | // write message to out 73 | out.print(messageBuffer.toString()); 74 | 75 | } 76 | 77 | private static int appendResponseLine(StringBuilder encodeBuf, MrcpRequest request) { 78 | String version = request.getVersion(); 79 | encodeBuf.append(version).append(' '); 80 | // message length will be inserted at this position after headers and content are encoded 81 | encodeBuf.append(' ').append(request.getMethodNameAsString()); 82 | encodeBuf.append(' ').append(request.getRequestID()); 83 | encodeBuf.append(CRLF); 84 | return version.length() + 1; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpResponseDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import org.mrcp4j.MrcpRequestState; 26 | import org.mrcp4j.message.MrcpResponse; 27 | 28 | import java.io.IOException; 29 | import java.text.ParseException; 30 | 31 | /** 32 | * Decodes response messages received in MRCPv2 format into {@link org.mrcp4j.message.MrcpResponse} instances. 33 | * 34 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 35 | */ 36 | public class MrcpResponseDecoder { 37 | 38 | private static final int RESPONSE_LINE_MRCP_VERSION_PART = 0; 39 | private static final int RESPONSE_LINE_MESSAGE_LENGTH_PART = 1; 40 | private static final int RESPONSE_LINE_REQUEST_ID_PART = 2; 41 | private static final int RESPONSE_LINE_STATUS_CODE_PART = 3; 42 | private static final int RESPONSE_LINE_REQUEST_STATE_PART = 4; 43 | private static final int RESPONSE_LINE_PART_COUNT = 5; 44 | 45 | public MrcpResponse createResponse(String responseLine) throws IOException, ParseException { 46 | 47 | if (responseLine == null || (responseLine = responseLine.trim()).length() < 1) { 48 | throw new ParseException("No response-line provided!", -1); 49 | } 50 | 51 | String[] responseLineParts = responseLine.split(" "); 52 | if (responseLineParts.length != RESPONSE_LINE_PART_COUNT) { 53 | throw new ParseException("Incorrect response-line format!", -1); 54 | } 55 | 56 | MrcpResponse response = new MrcpResponse(); 57 | 58 | // mrcp-version 59 | response.setVersion(responseLineParts[RESPONSE_LINE_MRCP_VERSION_PART]); //TODO: check if this matches request version, maybe at a higher level... 60 | 61 | // message-length 62 | try { 63 | response.setMessageLength( 64 | Integer.parseInt(responseLineParts[RESPONSE_LINE_MESSAGE_LENGTH_PART]) 65 | ); 66 | } catch (NumberFormatException e){ 67 | throw new ParseException("Incorrect message-length format!", -1); 68 | } 69 | 70 | // request-id 71 | try { 72 | response.setRequestID( 73 | Long.parseLong(responseLineParts[RESPONSE_LINE_REQUEST_ID_PART]) 74 | ); 75 | } catch (NumberFormatException e){ 76 | throw new ParseException("Incorrect request-id format!", -1); 77 | } 78 | 79 | // status-code 80 | try { 81 | response.setStatusCode( 82 | Short.parseShort(responseLineParts[RESPONSE_LINE_STATUS_CODE_PART]) 83 | ); 84 | } catch (NumberFormatException e){ 85 | throw new ParseException("Incorrect status-code format!", -1); 86 | } 87 | 88 | // request-state 89 | try { 90 | response.setRequestState( 91 | MrcpRequestState.fromString(responseLineParts[RESPONSE_LINE_REQUEST_STATE_PART]) 92 | ); 93 | } catch (IllegalArgumentException e){ 94 | throw (ParseException) new ParseException("Incorrect request-state format!", -1).initCause(e); 95 | } 96 | 97 | return response; 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/MrcpSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.client; 24 | 25 | import java.io.BufferedReader; 26 | import java.io.BufferedWriter; 27 | import java.io.IOException; 28 | import java.io.InputStreamReader; 29 | import java.io.OutputStreamWriter; 30 | import java.io.PrintWriter; 31 | import java.net.InetAddress; 32 | import java.net.Socket; 33 | import java.text.ParseException; 34 | import java.util.Collections; 35 | import java.util.HashMap; 36 | import java.util.Map; 37 | 38 | import org.apache.log4j.LogManager; 39 | import org.apache.log4j.Logger; 40 | import org.mrcp4j.message.MrcpMessage; 41 | import org.mrcp4j.message.header.ChannelIdentifier; 42 | import org.mrcp4j.message.header.IllegalValueException; 43 | import org.mrcp4j.message.request.MrcpRequest; 44 | 45 | /** 46 | * Provides an endpoint for communication between the MRCPv2 client and the MRCPv2 server (for internal library use only). 47 | * 48 | *

This class is intended for internal use by the MRCP4J implementation code. Please see 49 | * {@link org.mrcp4j.client.MrcpProvider#createChannel(java.lang.String, java.net.InetAddress, int, java.lang.String)} 50 | * for constructing an {@link org.mrcp4j.client.MrcpChannel} that can be used to send control messages to the media 51 | * resource on the MRCP server.

52 | * 53 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 54 | */ 55 | public class MrcpSocket { 56 | 57 | private static Logger _log = LogManager.getLogger(MrcpSocket.class); 58 | 59 | private MrcpRequestEncoder _requestEncoder = new MrcpRequestEncoder(); 60 | Map _handlers = Collections.synchronizedMap(new HashMap()); 61 | 62 | private Socket _socket; 63 | BufferedReader _in; 64 | private PrintWriter _out; 65 | 66 | MrcpSocket(InetAddress host, int port) throws IOException { 67 | _socket = new Socket(host, port); 68 | _in = new BufferedReader(new InputStreamReader(_socket.getInputStream())); 69 | _out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()))); 70 | new ReadThread().start(); 71 | } 72 | 73 | public void sendRequest(MrcpRequest request) throws IOException { 74 | try { 75 | _requestEncoder.encode(request, _out); 76 | _out.flush(); 77 | } catch (IOException e){ 78 | // TODO: may need to reset socket here... 79 | _log.debug(e, e); 80 | throw e; 81 | } 82 | } 83 | 84 | public void addMessageHandler(ChannelIdentifier channelID, MrcpMessageHandler handler) { 85 | _handlers.put(channelID, handler); 86 | } 87 | 88 | public void removeMessageHandler(ChannelIdentifier channelID) { 89 | _handlers.remove(channelID); 90 | } 91 | 92 | private class ReadThread extends Thread { 93 | 94 | private MrcpMessageDecoder _messageDecoder = new MrcpMessageDecoder(); 95 | 96 | /* (non-Javadoc) 97 | * @see java.lang.Runnable#run() 98 | */ 99 | @Override 100 | public void run() { 101 | boolean run = true; 102 | while (run) { 103 | // TODO: switch to nio so that the following statement doesn't block forever when the socket is closed 104 | try { 105 | MrcpMessage message = _messageDecoder.decode(_in); 106 | ChannelIdentifier channelID = message.getChannelIdentifier(); 107 | MrcpMessageHandler handler = _handlers.get(channelID); 108 | if (handler != null) { 109 | handler.handleMessage(message); 110 | } else if (_log.isDebugEnabled()) { 111 | _log.debug("No handler found for channel: " + channelID); 112 | } 113 | } catch (IOException e) { 114 | // TODO Auto-generated catch block 115 | run = false; 116 | _log.warn(e, e); 117 | } catch (ParseException e) { 118 | // TODO Auto-generated catch block 119 | _log.warn(e, e); 120 | } catch (IllegalValueException e) { 121 | // TODO Auto-generated catch block 122 | _log.warn(e, e); 123 | } 124 | } 125 | } 126 | 127 | } 128 | 129 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/client/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Provides interfaces and classes for implementing MRCPv2 clients. 31 | 32 |

Package Usage

33 | 34 |

The primary class for implementing MRCPv2 clients using MRCP4J is {@link org.mrcp4j.client.MrcpChannel}. All main client functions, such as sending requests and registering for events, are available through this class.

35 | 36 |

To construct an {@code MrcpChannel} instance use {@link org.mrcp4j.client.MrcpProvider#createChannel(java.lang.String, java.net.InetAddress, int, java.lang.String)}.

37 | 38 |

Related Documentation

39 | 40 | For overviews, tutorials, examples, guides, and tool documentation, please see: 41 | 44 | 45 | The latest draft of the MRCPv2 specification is available here. 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/MrcpEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message; 24 | 25 | import org.mrcp4j.MrcpEventName; 26 | 27 | /** 28 | * 29 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 30 | */ 31 | public class MrcpEvent extends MrcpServerMessage { 32 | 33 | private MrcpEventName _eventName; 34 | 35 | public void setEventName(MrcpEventName eventName) { 36 | _eventName = eventName; 37 | } 38 | 39 | public MrcpEventName getEventName() { 40 | return _eventName; 41 | } 42 | 43 | @Override 44 | protected final StringBuilder appendStartLine(StringBuilder sb) { 45 | sb.append(getVersion()); 46 | sb.append(' ').append(getMessageLength()); 47 | sb.append(' ').append(getEventName()); 48 | sb.append(' ').append(getRequestID()); 49 | sb.append(' ').append(getRequestState()); 50 | sb.append(CRLF); 51 | return sb; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/MrcpMessageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message; 24 | 25 | /** 26 | * 27 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 28 | */ 29 | public class MrcpMessageFactory { 30 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/MrcpServerMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message; 24 | 25 | import org.mrcp4j.MrcpRequestState; 26 | 27 | /** 28 | * 29 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 30 | */ 31 | public abstract class MrcpServerMessage extends MrcpMessage { 32 | 33 | private MrcpRequestState _requestState = MrcpRequestState.PENDING; 34 | 35 | public void setRequestState(MrcpRequestState requestState) { 36 | _requestState = requestState; 37 | } 38 | 39 | public MrcpRequestState getRequestState() { 40 | return _requestState; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/BaseValueFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | /** 26 | * Abstract {@link org.mrcp4j.message.header.ValueFactory} providing basic implementation for all methods other than the main object creation method. 27 | * 28 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 29 | */ 30 | public abstract class BaseValueFactory implements ValueFactory { 31 | 32 | private Class _valueClass; 33 | 34 | protected BaseValueFactory(Class valueClass) { 35 | _valueClass = valueClass; 36 | } 37 | 38 | /** 39 | * Subclasses should override this method if there is any limitation on the valid values of the objects generated by this factory. 40 | * @param valueObject object to be validated. 41 | * @throws IllegalValueException if the value of the object passed is not valid for this factory. 42 | */ 43 | protected void validateObject(Object valueObject) throws IllegalValueException { 44 | return; 45 | } 46 | 47 | /* (non-Javadoc) 48 | * @see org.mrcp4j.message.header.ValueFactory#toValueString(java.lang.Object) 49 | */ 50 | public String toValueString(Object valueObject) throws ClassCastException, IllegalArgumentException { 51 | if (!getValueClass().isAssignableFrom(valueObject.getClass())) { 52 | throw new ClassCastException("Illegal type for valueObject (expected " + 53 | getValueClass() + "): " + valueObject.getClass()); 54 | } 55 | 56 | try { 57 | validateObject(valueObject); 58 | } catch (IllegalValueException e) { 59 | throw new IllegalArgumentException(e); 60 | } 61 | 62 | return valueObject.toString(); 63 | } 64 | 65 | /* (non-Javadoc) 66 | * @see org.mrcp4j.message.header.ValueFactory#getValueClass() 67 | */ 68 | public Class getValueClass() { 69 | return _valueClass; 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/ChannelIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | import org.mrcp4j.MrcpResourceType; 26 | 27 | /** 28 | * 29 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 30 | */ 31 | public class ChannelIdentifier { 32 | 33 | private String _channelID; 34 | private MrcpResourceType _resourceType; 35 | private String _valueString; 36 | 37 | public ChannelIdentifier(String channelID, MrcpResourceType type) { 38 | this(channelID, type, constructValueString(channelID, type)); 39 | } 40 | 41 | ChannelIdentifier(String channelID, MrcpResourceType type, String valueString) { 42 | if (channelID == null || type == null || valueString == null) { 43 | throw new NullPointerException(); 44 | } 45 | _channelID = channelID; 46 | _resourceType = type; 47 | _valueString = valueString; 48 | } 49 | 50 | public String getChannelID() { 51 | return _channelID; 52 | } 53 | 54 | public MrcpResourceType getResourceType() { 55 | return _resourceType; 56 | } 57 | 58 | /* (non-Javadoc) 59 | * @see java.lang.Object#toString() 60 | */ 61 | @Override 62 | public String toString() { 63 | return _valueString; 64 | } 65 | 66 | /* (non-Javadoc) 67 | * @see java.lang.Object#equals(java.lang.Object) 68 | */ 69 | @Override 70 | public boolean equals(Object obj) { 71 | if (obj instanceof ChannelIdentifier) { 72 | return _valueString.equals(((ChannelIdentifier) obj)._valueString); 73 | } 74 | return false; 75 | } 76 | 77 | /* (non-Javadoc) 78 | * @see java.lang.Object#hashCode() 79 | */ 80 | @Override 81 | public int hashCode() { 82 | return _valueString.hashCode(); 83 | } 84 | 85 | private static String constructValueString(String channelID, MrcpResourceType type) { 86 | if (channelID == null || (channelID = channelID.trim()).length() < 1) { 87 | throw new IllegalArgumentException("Empty/null channel-id value: " + channelID); 88 | } 89 | if (type == null) { 90 | throw new NullPointerException("Null resource-type for channel-identifier not allowed!"); 91 | } 92 | 93 | StringBuilder sb = new StringBuilder(channelID); 94 | sb.append('@'); 95 | sb.append(type.toString()); 96 | return sb.toString(); 97 | } 98 | 99 | static class Factory extends BaseValueFactory { 100 | 101 | Factory() { 102 | super(ChannelIdentifier.class); 103 | } 104 | 105 | /* (non-Javadoc) 106 | * @see org.mrcp4j.message.header.ValueFactory#fromValueString(java.lang.String) 107 | */ 108 | public Object fromValueString(String valueString) throws IllegalValueException { 109 | String[] tokens = valueString.split("@"); 110 | if (tokens.length != 2) { 111 | throw new IllegalValueException("Illegal Channel-Identifier value: " + valueString); 112 | } 113 | MrcpResourceType resourceType = MrcpResourceType.fromString(tokens[1].trim()); 114 | return new ChannelIdentifier(tokens[0].trim(), resourceType, valueString); 115 | } 116 | 117 | } 118 | 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/CompletionCause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | /** 26 | * 27 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 28 | */ 29 | public class CompletionCause { 30 | 31 | private short _causeCode = -1; 32 | private String _causeName = null; 33 | private String _valueString = null; 34 | 35 | /** 36 | * @param causeCode coded value (000, 001, etc.) signifying the cause for request completion. 37 | * @param causeName textual representation of the cause for request completion. 38 | * @throws IllegalArgumentException if the Cause-Code or Cause-Name values provided are not valid. 39 | */ 40 | public CompletionCause(short causeCode, String causeName) throws IllegalArgumentException { 41 | this (causeCode, causeName, constructValueString(causeCode, causeName)); 42 | } 43 | 44 | CompletionCause(short causeCode, String causeName, String valueString) throws IllegalArgumentException { 45 | if (causeName == null || valueString == null) { 46 | throw new NullPointerException(); 47 | } 48 | _causeCode = causeCode; 49 | _causeName = causeName; 50 | _valueString = valueString; 51 | } 52 | 53 | /** 54 | * @return the Cause-Code. 55 | */ 56 | public short getCauseCode() { 57 | return _causeCode; 58 | } 59 | 60 | /** 61 | * @return the Cause-Name. 62 | */ 63 | public String getCauseName() { 64 | return _causeName; 65 | } 66 | 67 | /* (non-Javadoc) 68 | * @see java.lang.Object#toString() 69 | */ 70 | @Override 71 | public String toString() { 72 | return _valueString; 73 | } 74 | 75 | /* (non-Javadoc) 76 | * @see java.lang.Object#equals(java.lang.Object) 77 | */ 78 | @Override 79 | public boolean equals(Object obj) { 80 | if (obj instanceof CompletionCause) { 81 | return _valueString.equals(((CompletionCause) obj)._valueString); 82 | } 83 | return false; 84 | } 85 | 86 | /* (non-Javadoc) 87 | * @see java.lang.Object#hashCode() 88 | */ 89 | @Override 90 | public int hashCode() { 91 | return _causeCode; 92 | } 93 | 94 | private static String constructValueString(short causeCode, String causeName) throws IllegalArgumentException { 95 | if (causeCode < 0 || causeCode > 999) { 96 | throw new IllegalArgumentException("Illegal Cause-Code value: " + causeCode); 97 | } 98 | if (causeName == null || (causeName = causeName.trim()).length() < 1 || causeName.indexOf(' ') > -1) { 99 | throw new IllegalArgumentException("Illegal Cause-Name value: " + causeName); 100 | } 101 | 102 | StringBuilder sb = new StringBuilder(); 103 | if (causeCode < 100) { 104 | sb.append('0'); 105 | if (causeCode < 10) { 106 | sb.append('0'); 107 | } 108 | } 109 | sb.append(causeCode); 110 | sb.append(' '); 111 | sb.append(causeName); 112 | 113 | return sb.toString(); 114 | } 115 | 116 | static class Factory extends BaseValueFactory { 117 | 118 | Factory() { 119 | super(CompletionCause.class); 120 | } 121 | 122 | /* (non-Javadoc) 123 | * @see org.mrcp4j.message.header.ValueFactory#fromValueString(java.lang.String) 124 | */ 125 | public Object fromValueString(String valueString) throws IllegalValueException { 126 | String[] tokens = valueString.split(" "); 127 | if (tokens.length != 2) { 128 | throw new IllegalValueException("Illegal Completion-Cause header value: " + valueString); 129 | } 130 | 131 | try { 132 | short causeCode = Short.parseShort(tokens[0]); 133 | if (causeCode < 0 || causeCode > 999) { 134 | throw new IllegalValueException("Illegal Completion-Cause code: " + valueString); 135 | } 136 | return new CompletionCause(causeCode, tokens[1].trim(), valueString); 137 | } catch (NumberFormatException e) { 138 | throw new IllegalValueException("Illegal Completion-Cause code: " + valueString, e); 139 | } 140 | } 141 | 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/GenericValueFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | import java.lang.reflect.Constructor; 26 | import java.lang.reflect.InvocationTargetException; 27 | 28 | /** 29 | * 30 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 31 | */ 32 | public class GenericValueFactory extends BaseValueFactory { 33 | 34 | private Constructor _constructor; 35 | 36 | protected GenericValueFactory(Class valueClass) { 37 | super(valueClass); 38 | try { 39 | _constructor = valueClass.getConstructor(String.class); 40 | } catch (NoSuchMethodException e) { 41 | throw new Error(e); 42 | } 43 | } 44 | 45 | /* (non-Javadoc) 46 | * @see org.mrcp4j.message.header.ValueFactory#fromValueString(java.lang.String) 47 | */ 48 | public Object fromValueString(String valueString) throws IllegalValueException { 49 | try { 50 | Object valueObject = _constructor.newInstance(valueString); 51 | validateObject(valueObject); 52 | return valueObject; 53 | } catch (InvocationTargetException e) { 54 | Throwable cause = e.getCause(); 55 | if (cause instanceof Error) { 56 | throw (Error) cause; 57 | } 58 | if (cause instanceof IllegalValueException) { 59 | throw (IllegalValueException) cause; 60 | } 61 | throw new IllegalValueException("Illegal " + getValueClass().getName() + 62 | " value: " + valueString, (cause == null) ? e : cause); 63 | } catch (Exception e) { 64 | throw new Error(e); 65 | } 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/IllegalValueException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | import org.mrcp4j.MrcpException; 26 | 27 | /** 28 | * 29 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 30 | */ 31 | @SuppressWarnings("serial") 32 | public class IllegalValueException extends MrcpException { 33 | 34 | /** 35 | * 36 | */ 37 | public IllegalValueException() { 38 | super(); 39 | // TODO Auto-generated constructor stub 40 | } 41 | 42 | /** 43 | * @param message the error message 44 | */ 45 | public IllegalValueException(String message) { 46 | super(message); 47 | // TODO Auto-generated constructor stub 48 | } 49 | 50 | /** 51 | * @param message the error message 52 | * @param cause the root cause for this exception 53 | */ 54 | public IllegalValueException(String message, Throwable cause) { 55 | super(message, cause); 56 | // TODO Auto-generated constructor stub 57 | } 58 | 59 | /** 60 | * @param cause the root cause for this exception 61 | */ 62 | public IllegalValueException(Throwable cause) { 63 | super(cause); 64 | // TODO Auto-generated constructor stub 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/MrcpHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | /** 26 | * 27 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 28 | */ 29 | public class MrcpHeader { 30 | 31 | private MrcpHeaderName _name; 32 | private String _valueString; 33 | private Object _valueObject; 34 | 35 | /*public MrcpHeader(MrcpHeaderName name, Object valueObject) { 36 | this(name, valueObject.toString(), valueObject); 37 | }*/ 38 | 39 | MrcpHeader(MrcpHeaderName name, String valueString, Object valueObject) { 40 | _name = name; 41 | _valueString = valueString; 42 | _valueObject = valueObject; 43 | } 44 | 45 | public MrcpHeaderName getHeaderName() { 46 | return _name; 47 | } 48 | 49 | public String getNameString() { 50 | return _name.toString(); 51 | } 52 | 53 | public boolean isValidValue() { 54 | return !(_valueObject == null || _valueObject instanceof Throwable); 55 | } 56 | 57 | public Object getValueObject() throws IllegalValueException { 58 | if (_valueObject == null) { 59 | throw new IllegalValueException("Value object could not be constructed for value string: " + _valueString); 60 | } 61 | 62 | if (_valueObject instanceof Throwable) { 63 | if (_valueObject instanceof IllegalValueException) { 64 | throw (IllegalValueException) _valueObject; 65 | } 66 | throw new IllegalValueException("Value object could not be constructed for value string: " + 67 | _valueString, (Throwable) _valueObject); 68 | } 69 | 70 | return _valueObject; 71 | } 72 | 73 | public String getValueString() { 74 | return _valueString; 75 | } 76 | 77 | public StringBuilder appendTo(StringBuilder sb) { 78 | sb.append(_name); 79 | sb.append(":"); 80 | sb.append(_valueString); 81 | return sb; 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | return appendTo(new StringBuilder()).toString(); 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/RequestIdList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * 30 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 31 | */ 32 | public class RequestIdList { 33 | 34 | private List _idList = new ArrayList(); 35 | 36 | public void addRequestId(Long requestId) { 37 | _idList.add(requestId); 38 | } 39 | 40 | /** 41 | * @return Returns the list of request IDs. 42 | */ 43 | public List getIdList() { 44 | return new ArrayList(_idList); 45 | } 46 | 47 | /* (non-Javadoc) 48 | * @see java.lang.Object#toString() 49 | */ 50 | @Override 51 | public String toString() { 52 | StringBuilder sb = new StringBuilder(); 53 | for (Long id : _idList) { 54 | sb.append(id).append(','); 55 | } 56 | sb.setLength(sb.length() - 1); 57 | return sb.toString(); 58 | } 59 | 60 | static class Factory extends BaseValueFactory { 61 | 62 | Factory() { 63 | super(RequestIdList.class); 64 | } 65 | 66 | /* (non-Javadoc) 67 | * @see org.mrcp4j.message.header.ValueFactory#fromValueString(java.lang.String) 68 | */ 69 | public Object fromValueString(String valueString) throws IllegalValueException { 70 | RequestIdList instance = new RequestIdList(); 71 | String[] tokens = valueString.split(","); 72 | for (String token : tokens) { 73 | try { 74 | Long requestId = new Long(token.trim()); 75 | instance.addRequestId(requestId); 76 | } catch (NumberFormatException e) { 77 | throw new IllegalValueException("Illegal request-id-list value: " + valueString, e); 78 | } 79 | } 80 | return instance; 81 | } 82 | 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/ValueFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | /** 26 | * 27 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 28 | */ 29 | public interface ValueFactory { 30 | 31 | public Object fromValueString(String valueString) throws IllegalValueException; 32 | 33 | public String toValueString(Object valueObject) throws ClassCastException, IllegalArgumentException; 34 | 35 | public Class getValueClass(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/VendorSpecificHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.header; 24 | 25 | /** 26 | * 27 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 28 | */ 29 | public class VendorSpecificHeader extends MrcpHeader { 30 | 31 | private String _nameString; 32 | private String _valueString; 33 | 34 | public VendorSpecificHeader(String name, String value) { 35 | super(null, value, value); 36 | _nameString = name; 37 | _valueString = value; 38 | } 39 | 40 | public String getNameString() { 41 | return _nameString; 42 | } 43 | 44 | public StringBuilder appendTo(StringBuilder sb) { 45 | sb.append(_nameString); 46 | sb.append(":"); 47 | sb.append(_valueString); 48 | return sb; 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/header/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Provides classes for representing and constructing MRCPv2 headers and header values. 31 | 32 |

Package Usage

33 | 34 | Use {@link org.mrcp4j.message.header.MrcpHeaderName#createHeader(String,String)} to 35 | construct an {@link org.mrcp4j.message.header.MrcpHeader} instance. 36 | 37 |

Related Documentation

38 | 39 | For overviews, tutorials, examples, guides, and tool documentation, please see: 40 | 43 | 44 | The latest draft of the MRCPv2 specification is available here. 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Provides classes for representing the different MRCPv2 message types. 31 | 32 |

Related Documentation

33 | 34 | For overviews, tutorials, examples, guides, and tool documentation, please see: 35 | 38 | 39 | The latest draft of the MRCPv2 specification is available here. 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/request/MrcpRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.request; 24 | 25 | import org.mrcp4j.MrcpMethodName; 26 | import org.mrcp4j.message.MrcpMessage; 27 | 28 | /** 29 | * 30 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 31 | */ 32 | public abstract class MrcpRequest extends MrcpMessage { 33 | 34 | private MrcpMethodName _methodName; 35 | private String _methodNameAsString; 36 | 37 | protected MrcpRequest(MrcpMethodName methodName) { 38 | _methodName = methodName; 39 | } 40 | 41 | protected MrcpRequest(String sMethodName) { 42 | _methodNameAsString = sMethodName; 43 | } 44 | 45 | public MrcpMethodName getMethodName() { 46 | return _methodName; 47 | } 48 | 49 | public String getMethodNameAsString() { 50 | if (_methodName == null) 51 | return _methodNameAsString; 52 | else 53 | return _methodName.toString(); 54 | } 55 | 56 | @Override 57 | protected final StringBuilder appendStartLine(StringBuilder sb) { 58 | sb.append(getVersion()); 59 | sb.append(' ').append(getMessageLength()); 60 | sb.append(' ').append(getMethodNameAsString()); 61 | sb.append(' ').append(getRequestID()); 62 | sb.append(CRLF); 63 | return sb; 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/request/MrcpRequestFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.request; 24 | 25 | import org.mrcp4j.MrcpMethodName; 26 | 27 | /** 28 | * 29 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 30 | */ 31 | public class MrcpRequestFactory { 32 | 33 | private MrcpRequestFactory() { 34 | // restrict instance initialization to private access 35 | } 36 | 37 | public static MrcpRequest createRequest(String methodName) { 38 | return createRequest(MrcpMethodName.fromString(methodName)); 39 | } 40 | 41 | public static MrcpRequest createRequest(MrcpMethodName methodName) { 42 | MrcpRequest request = null; 43 | 44 | switch (methodName) { 45 | case RECORD: 46 | request = new RecordRequest(); 47 | break; 48 | 49 | case STOP: 50 | request = new StopRequest(); 51 | break; 52 | 53 | case START_INPUT_TIMERS: 54 | request = new StartInputTimersRequest(); 55 | break; 56 | 57 | default: 58 | request = new UnimplementedRequest(methodName); // TODO: should throw Exception instead when all possible methods have been specified 59 | } 60 | 61 | return request; 62 | } 63 | 64 | public static MrcpRequest createVendorSpecificRequest(String methodName) { 65 | MrcpRequest request = null; 66 | request = new UnimplementedRequest(methodName); 67 | return request; 68 | } 69 | 70 | // temporary class for unimplemented request types 71 | public static class UnimplementedRequest extends MrcpRequest { 72 | UnimplementedRequest(MrcpMethodName methodName) { 73 | super(methodName); 74 | } 75 | UnimplementedRequest(String methodName) { 76 | super(methodName); 77 | } 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/request/RecordRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.request; 24 | 25 | import org.mrcp4j.MrcpMethodName; 26 | import org.mrcp4j.message.header.MrcpHeader; 27 | import org.mrcp4j.message.header.MrcpHeaderName; 28 | 29 | /** 30 | * 31 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 32 | */ 33 | public class RecordRequest extends MrcpRequest { 34 | 35 | public RecordRequest() { 36 | super(MrcpMethodName.RECORD); 37 | } 38 | 39 | public String getMediaType() { 40 | MrcpHeader header = getHeader(MrcpHeaderName.MEDIA_TYPE); 41 | return (header == null) ? null : header.getValueString(); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/request/StartInputTimersRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.request; 24 | 25 | import org.mrcp4j.MrcpMethodName; 26 | 27 | /** 28 | * 29 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 30 | */ 31 | public class StartInputTimersRequest extends MrcpRequest { 32 | 33 | public StartInputTimersRequest() { 34 | super(MrcpMethodName.START_INPUT_TIMERS); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/request/StopRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.message.request; 24 | 25 | /** 26 | * 27 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 28 | */ 29 | import org.mrcp4j.MrcpMethodName; 30 | 31 | public class StopRequest extends MrcpRequest { 32 | 33 | public StopRequest() { 34 | super(MrcpMethodName.STOP); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/message/request/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Provides classes for representing and constructing MRCPv2 request messages. 31 | 32 |

Package Usage

33 | 34 | Use {@link org.mrcp4j.message.request.MrcpRequestFactory#createRequest(String)} or 35 | {@link org.mrcp4j.message.request.MrcpRequestFactory#createRequest(org.mrcp4j.MrcpMethodName)} to 36 | construct an {@link org.mrcp4j.message.request.MrcpRequest} instance. 37 | 38 |

Related Documentation

39 | 40 | For overviews, tutorials, examples, guides, and tool documentation, please see: 41 | 44 | 45 | The latest draft of the MRCPv2 specification is available here. 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | 31 | Provides common class and type definitions applicable to both MRCPv2 client and MRCPv2 server implementations. 32 | 33 |

Related Documentation

34 | 35 | For overviews, tutorials, examples, guides, and tool documentation, please see: 36 | 39 | 40 | The latest draft of the MRCPv2 specification is available here. 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/MrcpCodecFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server; 24 | 25 | import org.apache.mina.protocol.ProtocolCodecFactory; 26 | import org.apache.mina.protocol.ProtocolDecoder; 27 | import org.apache.mina.protocol.ProtocolEncoder; 28 | 29 | /** 30 | * 31 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 32 | */ 33 | public class MrcpCodecFactory implements ProtocolCodecFactory { 34 | 35 | public ProtocolDecoder newDecoder() { 36 | return new MrcpRequestDecoder(); 37 | } 38 | 39 | public ProtocolEncoder newEncoder() { 40 | return new MrcpMessageEncoder(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/MrcpMessageEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server; 24 | 25 | import static org.mrcp4j.message.MrcpMessage.CRLF; 26 | 27 | import org.mrcp4j.message.MrcpEvent; 28 | import org.mrcp4j.message.MrcpResponse; 29 | import org.mrcp4j.message.MrcpServerMessage; 30 | import org.mrcp4j.message.header.MrcpHeader; 31 | 32 | import org.apache.mina.common.ByteBuffer; 33 | import org.apache.mina.protocol.ProtocolEncoder; 34 | import org.apache.mina.protocol.ProtocolEncoderOutput; 35 | import org.apache.mina.protocol.ProtocolSession; 36 | import org.apache.mina.protocol.ProtocolViolationException; 37 | 38 | 39 | /** 40 | * Encodes {@link org.mrcp4j.message.MrcpMessage} instances into MRCPv2 specification format. 41 | * 42 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 43 | */ 44 | public class MrcpMessageEncoder implements ProtocolEncoder { 45 | 46 | private StringBuilder _encodeBuf = new StringBuilder(); 47 | 48 | public void encode(ProtocolSession session, Object message, ProtocolEncoderOutput out) 49 | throws ProtocolViolationException { 50 | 51 | // clear encode buffer 52 | _encodeBuf.delete(0, _encodeBuf.length()); 53 | 54 | // append start line 55 | int offset = -1; 56 | if (message instanceof MrcpResponse) { 57 | offset = appendResponseLine(_encodeBuf, ((MrcpResponse) message)); 58 | } else if (message instanceof MrcpEvent) { 59 | offset = appendEventLine(_encodeBuf, ((MrcpEvent) message)); 60 | } else { 61 | throw new ProtocolViolationException("Unsupported message type: " + message.getClass().getName()); 62 | } 63 | 64 | // append headers 65 | MrcpServerMessage serverMessage = (MrcpServerMessage) message; 66 | for (MrcpHeader header : serverMessage.getHeaders()) { 67 | _encodeBuf.append(header.toString()).append(CRLF); 68 | } 69 | 70 | // append CRLF line 71 | _encodeBuf.append(CRLF); 72 | 73 | // append message body if present 74 | if (serverMessage.hasContent()) { 75 | _encodeBuf.append(serverMessage.getContent()); 76 | } 77 | 78 | // determine and set message length 79 | int bufferLength = _encodeBuf.length(); 80 | int bufferLengthLength = Integer.toString(bufferLength).length(); 81 | int messageLength = bufferLength + bufferLengthLength; 82 | String messageLengthString = Integer.toString(messageLength); 83 | if (messageLengthString.length() > bufferLengthLength) { 84 | messageLengthString = Integer.toString(++messageLength); 85 | } 86 | _encodeBuf.insert(offset, messageLengthString); 87 | serverMessage.setMessageLength(messageLength); 88 | bufferLength = _encodeBuf.length(); 89 | 90 | // write _encodeBuf to out 91 | ByteBuffer bytes = ByteBuffer.allocate(bufferLength); 92 | for (int i = 0; i < bufferLength; i++) { 93 | bytes.put((byte) _encodeBuf.charAt(i)); 94 | } 95 | bytes.flip(); 96 | out.write(bytes); 97 | } 98 | 99 | private static int appendEventLine(StringBuilder encodeBuf, MrcpEvent event) { 100 | String version = event.getVersion(); 101 | encodeBuf.append(version).append(' '); 102 | // message length will be inserted at this position after headers and content are encoded 103 | encodeBuf.append(' ').append(event.getEventName()); 104 | encodeBuf.append(' ').append(event.getRequestID()); 105 | encodeBuf.append(' ').append(event.getRequestState()); 106 | encodeBuf.append(CRLF); 107 | return version.length() + 1; 108 | } 109 | 110 | private static int appendResponseLine(StringBuilder encodeBuf, MrcpResponse response) { 111 | String version = response.getVersion(); 112 | encodeBuf.append(version).append(' '); 113 | // message length will be inserted at this position after headers and content are encoded 114 | encodeBuf.append(' ').append(response.getRequestID()); 115 | encodeBuf.append(' ').append(response.getStatusCode()); 116 | encodeBuf.append(' ').append(response.getRequestState()); 117 | encodeBuf.append(CRLF); 118 | return version.length() + 1; 119 | } 120 | 121 | 122 | } -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/MrcpProtocolHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server; 24 | 25 | import org.mrcp4j.MrcpRequestState; 26 | import org.mrcp4j.message.MrcpEvent; 27 | import org.mrcp4j.message.MrcpResponse; 28 | import org.mrcp4j.message.request.MrcpRequest; 29 | 30 | import org.apache.mina.protocol.ProtocolHandlerAdapter; 31 | import org.apache.mina.protocol.ProtocolSession; 32 | 33 | /** 34 | * 35 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 36 | */ 37 | public class MrcpProtocolHandler extends ProtocolHandlerAdapter { 38 | 39 | private MrcpRequestProcessor _requestProcessor; 40 | 41 | public MrcpProtocolHandler(MrcpRequestProcessor requestProcessor) { 42 | _requestProcessor = requestProcessor; 43 | } 44 | 45 | /* (non-Javadoc) 46 | * @see org.apache.mina.protocol.ProtocolHandler#exceptionCaught(org.apache.mina.protocol.ProtocolSession, java.lang.Throwable) 47 | */ 48 | @Override 49 | public void exceptionCaught(ProtocolSession session, Throwable cause) { 50 | // close connection when unexpected exception is caught. 51 | session.close(); 52 | } 53 | 54 | /* (non-Javadoc) 55 | * @see org.apache.mina.protocol.ProtocolHandler#messageReceived(org.apache.mina.protocol.ProtocolSession, java.lang.Object) 56 | */ 57 | @Override 58 | public void messageReceived(ProtocolSession session, Object message) { 59 | MrcpRequest request = (MrcpRequest) message; 60 | new EventThread(_requestProcessor, session, request).start(); // TODO: move threading down chain 61 | } 62 | 63 | private static class EventThread extends Thread { 64 | 65 | private MrcpRequestProcessor _requestProcessor; 66 | private ProtocolSession _session; 67 | private MrcpRequest _request; 68 | 69 | EventThread(MrcpRequestProcessor requestProcessor, ProtocolSession session, MrcpRequest request) { 70 | _request = request; 71 | _requestProcessor = requestProcessor; 72 | _session = session; 73 | } 74 | 75 | /* (non-Javadoc) 76 | * @see java.lang.Runnable#run() 77 | */ 78 | @Override 79 | public void run() { 80 | MrcpResponse response = _requestProcessor.processRequest(_request); 81 | _session.write(response); 82 | 83 | MrcpRequestState requestState = response.getRequestState(); 84 | 85 | while (!requestState.equals(MrcpRequestState.COMPLETE) && _session.isConnected()) { 86 | MrcpEvent event = _requestProcessor.getNextEvent(_request); 87 | if (event != null) { 88 | _session.write(event); 89 | requestState = event.getRequestState(); 90 | } else { 91 | break; 92 | } 93 | } 94 | } 95 | } 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/MrcpRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server; 24 | 25 | import org.mrcp4j.message.MrcpResponse; 26 | import org.mrcp4j.message.request.MrcpRequest; 27 | 28 | /** 29 | * 30 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 31 | */ 32 | public interface MrcpRequestHandler { 33 | 34 | // TODOC: session cannot be used until this method has returned a response. 35 | // If the response does not complete the request the session should 36 | // be cached for handling future events for this request. 37 | public MrcpResponse handleRequest(MrcpRequest request, MrcpSession session); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/MrcpRequestProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server; 24 | 25 | import org.mrcp4j.message.MrcpEvent; 26 | import org.mrcp4j.message.MrcpResponse; 27 | import org.mrcp4j.message.request.MrcpRequest; 28 | 29 | /** 30 | * 31 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 32 | */ 33 | public interface MrcpRequestProcessor { 34 | 35 | public MrcpResponse processRequest(MrcpRequest request); 36 | 37 | public MrcpEvent getNextEvent(MrcpRequest request); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/MrcpSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server; 24 | 25 | import org.mrcp4j.MrcpEventName; 26 | import org.mrcp4j.MrcpRequestState; 27 | import org.mrcp4j.message.MrcpEvent; 28 | import org.mrcp4j.message.MrcpResponse; 29 | 30 | import java.util.concurrent.TimeoutException; 31 | 32 | /** 33 | * 34 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 35 | */ 36 | public interface MrcpSession { 37 | 38 | public MrcpResponse createResponse(short statusCode, MrcpRequestState requestState); 39 | 40 | public MrcpEvent createEvent(MrcpEventName eventName, MrcpRequestState requestState); 41 | 42 | public void postEvent(MrcpEvent event) 43 | throws TimeoutException, IllegalStateException; //TODO: should not throw TimeoutException 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/delegator/GenericRequestDelegator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.delegator; 24 | 25 | import org.mrcp4j.message.MrcpResponse; 26 | import org.mrcp4j.message.request.MrcpRequest; 27 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 28 | import org.mrcp4j.server.MrcpSession; 29 | import org.mrcp4j.server.provider.GenericRequestHandler; 30 | 31 | /** 32 | * 33 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 34 | */ 35 | public abstract class GenericRequestDelegator { 36 | 37 | private GenericRequestHandler _requestHandler; 38 | 39 | public GenericRequestDelegator(GenericRequestHandler requestHandler) { 40 | _requestHandler = requestHandler; 41 | } 42 | 43 | protected MrcpResponse setParams(MrcpRequest request, MrcpSession session) { 44 | return _requestHandler.setParams(((UnimplementedRequest) request), session); 45 | } 46 | 47 | protected MrcpResponse getParams(MrcpRequest request, MrcpSession session) { 48 | return _requestHandler.getParams(((UnimplementedRequest) request), session); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/delegator/RecogOnlyRequestDelegator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.delegator; 24 | 25 | import org.mrcp4j.message.MrcpResponse; 26 | import org.mrcp4j.message.request.MrcpRequest; 27 | import org.mrcp4j.message.request.StartInputTimersRequest; 28 | import org.mrcp4j.message.request.StopRequest; 29 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 30 | import org.mrcp4j.server.MrcpRequestHandler; 31 | import org.mrcp4j.server.MrcpSession; 32 | import org.mrcp4j.server.provider.RecogOnlyRequestHandler; 33 | 34 | /** 35 | * 36 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 37 | */ 38 | public class RecogOnlyRequestDelegator extends GenericRequestDelegator implements MrcpRequestHandler { 39 | 40 | private RecogOnlyRequestHandler _requestHandler; 41 | 42 | public RecogOnlyRequestDelegator(RecogOnlyRequestHandler requestHandler) { 43 | super(requestHandler); 44 | _requestHandler = requestHandler; 45 | } 46 | 47 | public MrcpResponse handleRequest(MrcpRequest request, MrcpSession session) { 48 | MrcpResponse response = null; 49 | 50 | switch (request.getMethodName()) { 51 | case SET_PARAMS: 52 | response = setParams(request, session); 53 | break; 54 | 55 | case GET_PARAMS: 56 | response = getParams(request, session); 57 | break; 58 | 59 | case DEFINE_GRAMMAR: 60 | response = defineGrammar(request, session); 61 | break; 62 | 63 | case RECOGNIZE: 64 | response = recognize(request, session); 65 | break; 66 | 67 | case INTERPRET: 68 | response = interpret(request, session); 69 | break; 70 | 71 | case GET_RESULT: 72 | response = getResult(request, session); 73 | break; 74 | 75 | case STOP: 76 | response = stop(request, session); 77 | break; 78 | 79 | case START_INPUT_TIMERS: 80 | response = startInputTimers(request, session); 81 | break; 82 | 83 | default: 84 | throw new IllegalArgumentException("Request method does not correspond to this resource type!"); 85 | 86 | } 87 | 88 | return response; 89 | } 90 | 91 | MrcpResponse defineGrammar(MrcpRequest request, MrcpSession session) { 92 | return _requestHandler.defineGrammar(((UnimplementedRequest) request), session); 93 | } 94 | 95 | MrcpResponse recognize(MrcpRequest request, MrcpSession session) { 96 | return _requestHandler.recognize(((UnimplementedRequest) request), session); 97 | } 98 | 99 | MrcpResponse interpret(MrcpRequest request, MrcpSession session) { 100 | return _requestHandler.interpret(((UnimplementedRequest) request), session); 101 | } 102 | 103 | MrcpResponse getResult(MrcpRequest request, MrcpSession session) { 104 | return _requestHandler.getResult(((UnimplementedRequest) request), session); 105 | } 106 | 107 | MrcpResponse stop(MrcpRequest request, MrcpSession session) { 108 | return _requestHandler.stop(((StopRequest) request), session); 109 | } 110 | 111 | MrcpResponse startInputTimers(MrcpRequest request, MrcpSession session) { 112 | return _requestHandler.startInputTimers(((StartInputTimersRequest) request), session); 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/delegator/RecorderRequestDelegator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.delegator; 24 | 25 | import org.mrcp4j.message.MrcpResponse; 26 | import org.mrcp4j.message.request.MrcpRequest; 27 | import org.mrcp4j.message.request.RecordRequest; 28 | import org.mrcp4j.message.request.StartInputTimersRequest; 29 | import org.mrcp4j.message.request.StopRequest; 30 | import org.mrcp4j.server.MrcpRequestHandler; 31 | import org.mrcp4j.server.MrcpSession; 32 | import org.mrcp4j.server.provider.RecorderRequestHandler; 33 | 34 | /** 35 | * 36 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 37 | */ 38 | public class RecorderRequestDelegator extends GenericRequestDelegator implements MrcpRequestHandler { 39 | 40 | private RecorderRequestHandler _requestHandler; 41 | 42 | public RecorderRequestDelegator(RecorderRequestHandler requestHandler) { 43 | super(requestHandler); 44 | _requestHandler = requestHandler; 45 | } 46 | 47 | public MrcpResponse handleRequest(MrcpRequest request, MrcpSession session) { 48 | MrcpResponse response = null; 49 | 50 | switch (request.getMethodName()) { 51 | case SET_PARAMS: 52 | response = setParams(request, session); 53 | break; 54 | 55 | case GET_PARAMS: 56 | response = getParams(request, session); 57 | break; 58 | 59 | case RECORD: 60 | response = record(request, session); 61 | break; 62 | 63 | case STOP: 64 | response = stop(request, session); 65 | break; 66 | 67 | case START_INPUT_TIMERS: 68 | response = startInputTimers(request, session); 69 | break; 70 | 71 | default: 72 | throw new IllegalArgumentException("Request method does not correspond to this resource type!"); 73 | 74 | } 75 | 76 | return response; 77 | } 78 | 79 | private MrcpResponse record(MrcpRequest request, MrcpSession session) { 80 | return _requestHandler.record(((RecordRequest) request), session); 81 | } 82 | 83 | private MrcpResponse stop(MrcpRequest request, MrcpSession session) { 84 | return _requestHandler.stop(((StopRequest) request), session); 85 | } 86 | 87 | private MrcpResponse startInputTimers(MrcpRequest request, MrcpSession session) { 88 | return _requestHandler.startInputTimers(((StartInputTimersRequest) request), session); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/delegator/SpeechSynthRequestDelegator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.delegator; 24 | 25 | import org.mrcp4j.message.MrcpResponse; 26 | import org.mrcp4j.message.request.MrcpRequest; 27 | import org.mrcp4j.message.request.StopRequest; 28 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 29 | import org.mrcp4j.server.MrcpRequestHandler; 30 | import org.mrcp4j.server.MrcpSession; 31 | import org.mrcp4j.server.provider.SpeechSynthRequestHandler; 32 | 33 | /** 34 | * 35 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 36 | */ 37 | public class SpeechSynthRequestDelegator extends GenericRequestDelegator implements MrcpRequestHandler { 38 | 39 | private SpeechSynthRequestHandler _requestHandler; 40 | 41 | public SpeechSynthRequestDelegator(SpeechSynthRequestHandler requestHandler) { 42 | super(requestHandler); 43 | _requestHandler = requestHandler; 44 | } 45 | 46 | public MrcpResponse handleRequest(MrcpRequest request, MrcpSession session) { 47 | MrcpResponse response = null; 48 | 49 | switch (request.getMethodName()) { 50 | case SET_PARAMS: 51 | response = setParams(request, session); 52 | break; 53 | 54 | case GET_PARAMS: 55 | response = getParams(request, session); 56 | break; 57 | 58 | case SPEAK: 59 | response = speak(request, session); 60 | break; 61 | 62 | case STOP: 63 | response = stop(request, session); 64 | break; 65 | 66 | case PAUSE: 67 | response = pause(request, session); 68 | break; 69 | 70 | case RESUME: 71 | response = resume(request, session); 72 | break; 73 | 74 | case BARGE_IN_OCCURRED: 75 | response = bargeInOccurred(request, session); 76 | break; 77 | 78 | case CONTROL: 79 | response = control(request, session); 80 | break; 81 | 82 | case DEFINE_LEXICON: 83 | response = defineLexicon(request, session); 84 | break; 85 | 86 | default: 87 | throw new IllegalArgumentException("Request method does not correspond to this resource type!"); 88 | 89 | } 90 | 91 | return response; 92 | } 93 | 94 | private MrcpResponse speak(MrcpRequest request, MrcpSession session) { 95 | return _requestHandler.speak(((UnimplementedRequest) request), session); 96 | } 97 | 98 | private MrcpResponse stop(MrcpRequest request, MrcpSession session) { 99 | return _requestHandler.stop(((StopRequest) request), session); 100 | } 101 | 102 | private MrcpResponse pause(MrcpRequest request, MrcpSession session) { 103 | return _requestHandler.pause(((UnimplementedRequest) request), session); 104 | } 105 | 106 | private MrcpResponse resume(MrcpRequest request, MrcpSession session) { 107 | return _requestHandler.resume(((UnimplementedRequest) request), session); 108 | } 109 | 110 | private MrcpResponse bargeInOccurred(MrcpRequest request, MrcpSession session) { 111 | return _requestHandler.bargeInOccurred(((UnimplementedRequest) request), session); 112 | } 113 | 114 | private MrcpResponse control(MrcpRequest request, MrcpSession session) { 115 | return _requestHandler.control(((UnimplementedRequest) request), session); 116 | } 117 | 118 | private MrcpResponse defineLexicon(MrcpRequest request, MrcpSession session) { 119 | return _requestHandler.defineLexicon(((UnimplementedRequest) request), session); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/delegator/VoiceEnrollmentRequestDelegator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.delegator; 24 | 25 | import org.mrcp4j.message.MrcpResponse; 26 | import org.mrcp4j.message.request.MrcpRequest; 27 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 28 | import org.mrcp4j.server.MrcpRequestHandler; 29 | import org.mrcp4j.server.MrcpSession; 30 | import org.mrcp4j.server.provider.VoiceEnrollmentRequestHandler; 31 | 32 | /** 33 | * 34 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 35 | */ 36 | public class VoiceEnrollmentRequestDelegator extends RecogOnlyRequestDelegator implements MrcpRequestHandler { 37 | 38 | private VoiceEnrollmentRequestHandler _requestHandler; 39 | 40 | public VoiceEnrollmentRequestDelegator(VoiceEnrollmentRequestHandler requestHandler) { 41 | super(requestHandler); 42 | _requestHandler = requestHandler; 43 | } 44 | 45 | @Override 46 | public MrcpResponse handleRequest(MrcpRequest request, MrcpSession session) { 47 | MrcpResponse response = null; 48 | 49 | switch (request.getMethodName()) { 50 | case SET_PARAMS: 51 | response = setParams(request, session); 52 | break; 53 | 54 | case GET_PARAMS: 55 | response = getParams(request, session); 56 | break; 57 | 58 | case DEFINE_GRAMMAR: 59 | response = defineGrammar(request, session); 60 | break; 61 | 62 | case RECOGNIZE: 63 | response = recognize(request, session); 64 | break; 65 | 66 | case INTERPRET: 67 | response = interpret(request, session); 68 | break; 69 | 70 | case GET_RESULT: 71 | response = getResult(request, session); 72 | break; 73 | 74 | case STOP: 75 | response = stop(request, session); 76 | break; 77 | 78 | case START_INPUT_TIMERS: 79 | response = startInputTimers(request, session); 80 | break; 81 | 82 | case START_PHRASE_ENROLLMENT: 83 | response = startPhraseEnrollment(request, session); 84 | break; 85 | 86 | case ENROLLMENT_ROLLBACK: 87 | response = enrollmentRollback(request, session); 88 | break; 89 | 90 | case END_PHRASE_ENROLLMENT: 91 | response = endPhraseEnrollment(request, session); 92 | break; 93 | 94 | case MODIFY_PHRASE: 95 | response = modifyPhrase(request, session); 96 | break; 97 | 98 | case DELETE_PHRASE: 99 | response = deletePhrase(request, session); 100 | break; 101 | 102 | default: 103 | throw new IllegalArgumentException("Request method does not correspond to this resource type!"); 104 | 105 | } 106 | 107 | return response; 108 | } 109 | 110 | private MrcpResponse startPhraseEnrollment(MrcpRequest request, MrcpSession session) { 111 | return _requestHandler.startPhraseEnrollment(((UnimplementedRequest) request), session); 112 | } 113 | 114 | private MrcpResponse enrollmentRollback(MrcpRequest request, MrcpSession session) { 115 | return _requestHandler.enrollmentRollback(((UnimplementedRequest) request), session); 116 | } 117 | 118 | private MrcpResponse endPhraseEnrollment(MrcpRequest request, MrcpSession session) { 119 | return _requestHandler.endPhraseEnrollment(((UnimplementedRequest) request), session); 120 | } 121 | 122 | private MrcpResponse modifyPhrase(MrcpRequest request, MrcpSession session) { 123 | return _requestHandler.modifyPhrase(((UnimplementedRequest) request), session); 124 | } 125 | 126 | private MrcpResponse deletePhrase(MrcpRequest request, MrcpSession session) { 127 | return _requestHandler.deletePhrase(((UnimplementedRequest) request), session); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/delegator/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Provides request handlers which delegate MRCPv2 requests to the appropriate request handler method. 31 | 32 |

Related Documentation

33 | 34 | For overviews, tutorials, examples, guides, and tool documentation, please see: 35 | 38 | 39 | The latest draft of the MRCPv2 specification is available here. 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/mina/IoTextLoggingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.mina; 24 | 25 | import org.apache.log4j.LogManager; 26 | import org.apache.log4j.Logger; 27 | import org.apache.mina.common.ByteBuffer; 28 | import org.apache.mina.common.IdleStatus; 29 | import org.apache.mina.io.IoFilter; 30 | import org.apache.mina.io.IoSession; 31 | 32 | /** 33 | * 34 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 35 | */ 36 | public class IoTextLoggingFilter implements IoFilter { 37 | 38 | /** 39 | * Name of the log used for logging session events. 40 | */ 41 | public static final String SESSION_LOG_NAME = "org.mrcp4j.server.SESSION"; 42 | 43 | private static Logger _log = LogManager.getLogger(SESSION_LOG_NAME); 44 | 45 | /* (non-Javadoc) 46 | * @see org.apache.mina.io.IoFilter#sessionOpened(org.apache.mina.io.IoFilter.NextFilter, 47 | * org.apache.mina.io.IoSession) 48 | */ 49 | public void sessionOpened(NextFilter nextFilter, IoSession session) { 50 | _log.debug("OPENED"); 51 | nextFilter.sessionOpened(session); 52 | } 53 | 54 | /* (non-Javadoc) 55 | * @see org.apache.mina.io.IoFilter#sessionClosed(org.apache.mina.io.IoFilter.NextFilter, 56 | * org.apache.mina.io.IoSession) 57 | */ 58 | public void sessionClosed(NextFilter nextFilter, IoSession session) { 59 | _log.debug("CLOSED"); 60 | nextFilter.sessionClosed(session); 61 | } 62 | 63 | /* (non-Javadoc) 64 | * @see org.apache.mina.io.IoFilter#sessionIdle(org.apache.mina.io.IoFilter.NextFilter, 65 | * org.apache.mina.io.IoSession, org.apache.mina.common.IdleStatus) 66 | */ 67 | public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) { 68 | if (_log.isDebugEnabled()) { 69 | _log.debug("IDLE: " + status); 70 | } 71 | nextFilter.sessionIdle(session, status); 72 | } 73 | 74 | /* (non-Javadoc) 75 | * @see org.apache.mina.io.IoFilter#exceptionCaught(org.apache.mina.io.IoFilter.NextFilter, 76 | * org.apache.mina.io.IoSession, java.lang.Throwable) 77 | */ 78 | public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) { 79 | _log.warn("EXCEPTION: " + cause.getMessage() + '\n', cause); 80 | nextFilter.exceptionCaught(session, cause); 81 | } 82 | 83 | /* (non-Javadoc) 84 | * @see org.apache.mina.io.IoFilter#dataRead(org.apache.mina.io.IoFilter.NextFilter, 85 | * org.apache.mina.io.IoSession, org.apache.mina.common.ByteBuffer) 86 | */ 87 | public void dataRead(NextFilter nextFilter, IoSession session, ByteBuffer buf) { 88 | if (_log.isDebugEnabled()) { 89 | _log.debug("READ:\n" + getAndReset(buf)); 90 | } 91 | nextFilter.dataRead(session, buf); 92 | } 93 | 94 | /* (non-Javadoc) 95 | * @see org.apache.mina.io.IoFilter#dataWritten(org.apache.mina.io.IoFilter.NextFilter, 96 | * org.apache.mina.io.IoSession, java.lang.Object) 97 | */ 98 | public void dataWritten(NextFilter nextFilter, IoSession session, Object marker) { 99 | if (_log.isDebugEnabled()) { 100 | _log.debug("WRITTEN:\n" + marker); 101 | } 102 | nextFilter.dataWritten(session, marker); 103 | } 104 | 105 | /* (non-Javadoc) 106 | * @see org.apache.mina.io.IoFilter#filterWrite(org.apache.mina.io.IoFilter.NextFilter, 107 | * org.apache.mina.io.IoSession, org.apache.mina.common.ByteBuffer, 108 | * java.lang.Object) 109 | */ 110 | public void filterWrite(NextFilter nextFilter, IoSession session, ByteBuffer buf, Object marker) { 111 | if (_log.isTraceEnabled()) { 112 | _log.trace("WRITE:\n" + marker + "\n[ByteBuffer]:\n" + getAndReset(buf)); 113 | } 114 | nextFilter.filterWrite(session, buf, marker); 115 | } 116 | 117 | private static String getAndReset(ByteBuffer buf) { 118 | StringBuilder sb = new StringBuilder(); 119 | while (buf.hasRemaining()) { 120 | sb.append((char) buf.get()); 121 | } 122 | buf.rewind(); 123 | return sb.toString(); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/mina/SimpleProtocolProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.mina; 24 | 25 | import org.apache.mina.protocol.ProtocolCodecFactory; 26 | import org.apache.mina.protocol.ProtocolHandler; 27 | import org.apache.mina.protocol.ProtocolProvider; 28 | 29 | /** 30 | * 31 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 32 | */ 33 | public class SimpleProtocolProvider implements ProtocolProvider { 34 | 35 | private ProtocolHandler _protocolHandler; 36 | private ProtocolCodecFactory _codecFactory; 37 | 38 | public SimpleProtocolProvider(ProtocolCodecFactory codecFactory, ProtocolHandler protocolHandler) { 39 | _codecFactory = codecFactory; 40 | _protocolHandler = protocolHandler; 41 | } 42 | 43 | public ProtocolCodecFactory getCodecFactory() { 44 | return _codecFactory; 45 | } 46 | 47 | public ProtocolHandler getHandler() { 48 | return _protocolHandler; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/mina/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Provides classes for working with the Apache MINA network application framework. 31 | 32 |

Related Documentation

33 | 34 | For overviews, tutorials, examples, guides, and tool documentation, please see: 35 | 38 | 39 | The latest draft of the MRCPv2 specification is available here. 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Provides interfaces and classes for implementing MRCPv2 servers. 31 | 32 |

Package Usage

33 | 34 |

MRCPv2 servers can be implemented by registering a request handler implementation (see the 35 | {@link org.mrcp4j.server.provider} package for request handler interfaces) with an 36 | {@link org.mrcp4j.server.MrcpServerSocket} via the appropriate {@code openChannel()} method call.

37 | 38 |

Related Documentation

39 | 40 | For overviews, tutorials, examples, guides, and tool documentation, please see: 41 | 44 | 45 | The latest draft of the MRCPv2 specification is available here. 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/provider/GenericRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.provider; 24 | 25 | import org.mrcp4j.message.MrcpResponse; 26 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 27 | import org.mrcp4j.server.MrcpSession; 28 | 29 | /** 30 | * 31 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 32 | */ 33 | public interface GenericRequestHandler { 34 | /* 35 | generic-method = "SET-PARAMS" 36 | / "GET-PARAMS" 37 | */ 38 | public MrcpResponse setParams(UnimplementedRequest request, MrcpSession session); 39 | 40 | public MrcpResponse getParams(UnimplementedRequest request, MrcpSession session); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/provider/RecogOnlyRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.provider; 24 | 25 | import org.mrcp4j.MrcpResourceType; 26 | import org.mrcp4j.message.MrcpResponse; 27 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 28 | import org.mrcp4j.message.request.StartInputTimersRequest; 29 | import org.mrcp4j.message.request.StopRequest; 30 | import org.mrcp4j.server.MrcpSession; 31 | 32 | /** 33 | * 34 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 35 | */ 36 | public interface RecogOnlyRequestHandler extends GenericRequestHandler { 37 | 38 | public static final MrcpResourceType[] RESOURCE_TYPES = { 39 | MrcpResourceType.DTMFRECOG, 40 | MrcpResourceType.SPEECHRECOG 41 | }; 42 | 43 | /* 44 | recog-only-method = "DEFINE-GRAMMAR" ; A 45 | / "RECOGNIZE" ; B 46 | / "INTERPRET" ; C 47 | / "GET-RESULT" ; D 48 | / "START-INPUT-TIMERS" ; E 49 | / "STOP" ; F 50 | */ 51 | 52 | public MrcpResponse defineGrammar(UnimplementedRequest request, MrcpSession session); 53 | 54 | public MrcpResponse recognize(UnimplementedRequest request, MrcpSession session); 55 | 56 | public MrcpResponse interpret(UnimplementedRequest request, MrcpSession session); 57 | 58 | public MrcpResponse getResult(UnimplementedRequest request, MrcpSession session); 59 | 60 | public MrcpResponse startInputTimers(StartInputTimersRequest request, MrcpSession session); 61 | 62 | public MrcpResponse stop(StopRequest request, MrcpSession session); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/provider/RecorderRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.provider; 24 | 25 | import org.mrcp4j.MrcpResourceType; 26 | import org.mrcp4j.message.MrcpResponse; 27 | import org.mrcp4j.message.request.RecordRequest; 28 | import org.mrcp4j.message.request.StartInputTimersRequest; 29 | import org.mrcp4j.message.request.StopRequest; 30 | import org.mrcp4j.server.MrcpSession; 31 | 32 | /** 33 | * 34 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 35 | */ 36 | public interface RecorderRequestHandler extends GenericRequestHandler { 37 | 38 | public static final MrcpResourceType[] RESOURCE_TYPES = { MrcpResourceType.RECORDER }; 39 | 40 | /* 41 | recorder-Method = "RECORD" ; A 42 | / "STOP" ; B 43 | / "START-INPUT-TIMERS" ; C 44 | */ 45 | 46 | public MrcpResponse record(RecordRequest request, MrcpSession session); 47 | 48 | public MrcpResponse stop(StopRequest request, MrcpSession session); 49 | 50 | public MrcpResponse startInputTimers(StartInputTimersRequest request, MrcpSession session); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/provider/SpeakVerifyRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.provider; 24 | 25 | import org.mrcp4j.MrcpResourceType; 26 | import org.mrcp4j.message.MrcpResponse; 27 | import org.mrcp4j.message.request.StopRequest; 28 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 29 | import org.mrcp4j.server.MrcpSession; 30 | 31 | /** 32 | * 33 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 34 | */ 35 | public interface SpeakVerifyRequestHandler extends GenericRequestHandler { 36 | 37 | public static final MrcpResourceType[] RESOURCE_TYPES = { MrcpResourceType.SPEAKVERIFY }; 38 | 39 | /* 40 | verifier-method = "START-SESSION" ; A 41 | / "END-SESSION" ; B 42 | / "QUERY-VOICEPRINT" ; C 43 | / "DELETE-VOICEPRINT" ; D 44 | / "VERIFY" ; E 45 | / "VERIFY-FROM-BUFFER" ; F 46 | / "VERIFY-ROLLBACK" ; G 47 | / "STOP" ; H 48 | / "CLEAR-BUFFER" ; I 49 | / "START-INPUT-TIMERS" ; J 50 | / "GET-INTERMEDIATE-RESULT" ; K 51 | */ 52 | 53 | public MrcpResponse startSession(UnimplementedRequest request, MrcpSession session); 54 | 55 | public MrcpResponse endSession(UnimplementedRequest request, MrcpSession session); 56 | 57 | public MrcpResponse queryVoiceprint(UnimplementedRequest request, MrcpSession session); 58 | 59 | public MrcpResponse deleteVoiceprint(UnimplementedRequest request, MrcpSession session); 60 | 61 | public MrcpResponse verify(UnimplementedRequest request, MrcpSession session); 62 | 63 | public MrcpResponse verifyFromBuffer(UnimplementedRequest request, MrcpSession session); 64 | 65 | public MrcpResponse verifyRollback(UnimplementedRequest request, MrcpSession session); 66 | 67 | public MrcpResponse stop(StopRequest request, MrcpSession session); 68 | 69 | public MrcpResponse clearBuffer(UnimplementedRequest request, MrcpSession session); 70 | 71 | public MrcpResponse startInputTimers(UnimplementedRequest request, MrcpSession session); 72 | 73 | public MrcpResponse getIntermediateResult(UnimplementedRequest request, MrcpSession session); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/provider/SpeechSynthRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.provider; 24 | 25 | import org.mrcp4j.MrcpResourceType; 26 | import org.mrcp4j.message.MrcpResponse; 27 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 28 | import org.mrcp4j.message.request.StopRequest; 29 | import org.mrcp4j.server.MrcpSession; 30 | 31 | /** 32 | * 33 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 34 | */ 35 | public interface SpeechSynthRequestHandler extends GenericRequestHandler { 36 | 37 | public static final MrcpResourceType[] RESOURCE_TYPES = { 38 | MrcpResourceType.BASICSYNTH, 39 | MrcpResourceType.SPEECHSYNTH 40 | }; 41 | 42 | /* 43 | synthesizer-method = "SPEAK" ; A 44 | / "STOP" ; B 45 | / "PAUSE" ; C 46 | / "RESUME" ; D 47 | / "BARGE-IN-OCCURRED" ; E 48 | / "CONTROL" ; F 49 | / "DEFINE-LEXICON" ; G 50 | */ 51 | 52 | public MrcpResponse speak(UnimplementedRequest request, MrcpSession session); 53 | 54 | public MrcpResponse stop(StopRequest request, MrcpSession session); 55 | 56 | public MrcpResponse pause(UnimplementedRequest request, MrcpSession session); 57 | 58 | public MrcpResponse resume(UnimplementedRequest request, MrcpSession session); 59 | 60 | public MrcpResponse bargeInOccurred(UnimplementedRequest request, MrcpSession session); 61 | 62 | public MrcpResponse control(UnimplementedRequest request, MrcpSession session); 63 | 64 | public MrcpResponse defineLexicon(UnimplementedRequest request, MrcpSession session); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/provider/VoiceEnrollmentRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.server.provider; 24 | 25 | import org.mrcp4j.MrcpResourceType; 26 | import org.mrcp4j.message.MrcpResponse; 27 | import org.mrcp4j.message.request.MrcpRequestFactory.UnimplementedRequest; 28 | import org.mrcp4j.server.MrcpSession; 29 | 30 | /** 31 | * 32 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 33 | */ 34 | public interface VoiceEnrollmentRequestHandler extends RecogOnlyRequestHandler { 35 | 36 | public static final MrcpResourceType[] RESOURCE_TYPES = RecogOnlyRequestHandler.RESOURCE_TYPES; 37 | 38 | /* 39 | enrollment-method = "START-PHRASE-ENROLLMENT" ; G 40 | / "ENROLLMENT-ROLLBACK" ; H 41 | / "END-PHRASE-ENROLLMENT" ; I 42 | / "MODIFY-PHRASE" ; J 43 | / "DELETE-PHRASE" ; K 44 | */ 45 | 46 | public MrcpResponse startPhraseEnrollment(UnimplementedRequest request, MrcpSession session); 47 | 48 | public MrcpResponse enrollmentRollback(UnimplementedRequest request, MrcpSession session); 49 | 50 | public MrcpResponse endPhraseEnrollment(UnimplementedRequest request, MrcpSession session); 51 | 52 | public MrcpResponse modifyPhrase(UnimplementedRequest request, MrcpSession session); 53 | 54 | public MrcpResponse deletePhrase(UnimplementedRequest request, MrcpSession session); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/server/provider/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Defines the interfaces to be implemented by an MRCPv2 resource provider. 31 | 32 |

Related Documentation

33 | 34 | For overviews, tutorials, examples, guides, and tool documentation, please see: 35 | 38 | 39 | The latest draft of the MRCPv2 specification is available here. 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/util/ObjectWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.util; 24 | 25 | /** 26 | * Utility class for wrapping object references. The primary purpose of this class 27 | * is to allow for null values to be passed to methods that may not accept null values. 28 | * For example posting a null value to a java.util.concurrent.BlockingQueue. 29 | * 30 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 31 | * 32 | * @param type of the object being wrapped 33 | */ 34 | public class ObjectWrapper { 35 | 36 | private O _obj; 37 | 38 | /** 39 | * Constructs an instance that wraps the specified object. 40 | * @param obj object to be wrapped. Null values allowed. 41 | */ 42 | public ObjectWrapper(O obj) { 43 | _obj = obj; 44 | } 45 | 46 | /** 47 | * Gets the object wrapped by this instance. 48 | * @return the wrapped object or null if this instance wraps a null. 49 | */ 50 | public O getObject() { 51 | return _obj; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/util/ThrowingQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MRCP4J - Java API implementation of MRCPv2 specification 3 | * 4 | * Copyright (C) 2005-2006 SpeechForge - http://www.speechforge.org 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 19 | * 20 | * Contact: ngodfredsen@users.sourceforge.net 21 | * 22 | */ 23 | package org.mrcp4j.util; 24 | 25 | import java.util.concurrent.BlockingQueue; 26 | import java.util.concurrent.LinkedBlockingQueue; 27 | 28 | /** 29 | * 30 | * @author Niels Godfredsen {@literal <}ngodfredsen@users.sourceforge.net{@literal >} 31 | * @param the type of elements held in this queue 32 | * @param the type of throwable that can be thrown by this queue 33 | * 34 | */ 35 | public class ThrowingQueue { 36 | 37 | private BlockingQueue _queue = new LinkedBlockingQueue(); 38 | 39 | public void put(E element) throws InterruptedException { 40 | Wrapper wrapper = new Wrapper(element); 41 | _queue.put(wrapper); 42 | } 43 | 44 | public void put(T e) throws InterruptedException { 45 | Wrapper wrapper = new Wrapper(e); 46 | _queue.put(wrapper); 47 | } 48 | 49 | public E take() throws T, InterruptedException { 50 | Wrapper wrapper = _queue.take(); 51 | return wrapper.getElement(); 52 | } 53 | 54 | private class Wrapper { 55 | 56 | private T _t; 57 | private E _element; 58 | 59 | /** 60 | * TODOC 61 | * @param element 62 | */ 63 | public Wrapper(E element) { 64 | super(); 65 | // TODO Auto-generated constructor stub 66 | _element = element; 67 | } 68 | 69 | /** 70 | * TODOC 71 | * @param t 72 | */ 73 | public Wrapper(T t) { 74 | _t = t; 75 | } 76 | 77 | /** 78 | * TODOC 79 | * @return Returns the element. 80 | * @throws T 81 | */ 82 | public E getElement() throws T { 83 | if (_t != null) { 84 | throw _t; 85 | } 86 | return _element; 87 | } 88 | 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/mrcp4j/util/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | Provides utility classes required by various components of the MRCP4J library. 31 | 32 |

Related Documentation

33 | 34 | For overviews, tutorials, examples, guides, and tool documentation, please see: 35 | 38 | 39 | The latest draft of the MRCPv2 specification is available here. 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/site/apt/changelog.apt: -------------------------------------------------------------------------------- 1 | ----- 2 | Change Log 3 | ----- 4 | Niels Godfredsen 5 | ----- 6 | 7 | 8 | Change Log for MRCP4J 9 | 10 | * MRCP4J {v0.2} 11 | 12 | * Fix potential deadlock in event queue timeout scenario. 13 | 14 | * Remove redundant signal for event queue completion which was causing MrcpSession.postEvent() to hang. 15 | 16 | * Use commons-logging for debug output instead of System.out.println() statements. 17 | 18 | * Use commons-logging for MRCP session logging instead of MINA session log. 19 | 20 | * Update MINA dependency from version 0.7.2 to version 0.8.0. 21 | 22 | * Add value factories for some of the more commonly used MRCP headers. 23 | 24 | * Preserve the order of MRCP headers to be the same as the order they are added in. 25 | 26 | * Calculate and set message-length during encoding of MRCP messages. 27 | 28 | * Terminate message content with CRLF and include in calculation of content-length header value. 29 | 30 | 31 | * MRCP4J {v0.1} 32 | 33 | No prior release to compare with. 34 | -------------------------------------------------------------------------------- /src/site/apt/doc.apt: -------------------------------------------------------------------------------- 1 | ----- 2 | Documentation 3 | ----- 4 | Niels Godfredsen 5 | ----- 6 | 7 | 8 | Documentation 9 | 10 | * API Documentation 11 | 12 | The latest version of the MRCP4J API docs can be accessed {{{docs/apidocs/index.html?overview-summary.html}here}}. 13 | 14 | * Change Log 15 | 16 | * {{{changelog.html#v0.2}MRCP4J v0.2}} 17 | 18 | * {{{changelog.html#v0.1}MRCP4J v0.1}} 19 | -------------------------------------------------------------------------------- /src/site/apt/index.apt: -------------------------------------------------------------------------------- 1 | ----- 2 | Overview 3 | ----- 4 | Niels Godfredsen 5 | ----- 6 | 7 | Welcome to MRCP4J 8 | 9 | MRCP4J provides a Java API that encapsulates the MRCPv2 protocol and can be used to implement MRCPv2 clients and/or servers. 10 | 11 | What is MRCPv2? 12 | 13 | Media Resource Control Protocol Version 2 is a protocol being developed by the Speech Services Control Working Group 14 | ({{{http://www.ietf.org/html.charters/speechsc-charter.html}Speechsc}}) of the Internet Engineering Task Force 15 | ({{{http://www.ietf.org}IETF}}) to allow client hosts to control media processing resources such as speech synthesizers, 16 | speech recognizers, speaker verifiers and speaker identifiers residing in servers on the network. 17 | 18 | From the introduction of the MRCPv2 draft specification: 19 | 20 | ------------------- 21 | The MRCPv2 protocol is designed to allow a client device to control 22 | media processing resources on the network. Some of these media 23 | processing resources include speech recognition engines, speech 24 | synthesis engines, speaker verification and speaker identification 25 | engines. MRCPv2 enables the implementation of distributed 26 | Interactive Voice Response platforms using VoiceXML browsers or 27 | other client applications while maintaing separate back-end speech 28 | processing capabilities on specialized speech processing servers. 29 | MRCPv2 is based on the earlier Media Resource Control Protocol (MRCP) 30 | developed jointly by Cisco Systems, Inc., Nuance Communications, 31 | and Speechworks Inc. 32 | ------------------- 33 | 34 | You can read the full text of the latest MRCPv2 draft {{{http://tools.ietf.org/html/draft-ietf-speechsc-mrcpv2}here}}. 35 | 36 | Latest News 37 | 38 | *MRCP4J v0.2 Released - August 30, 2006 39 | 40 | "The MRCPv2 protocol is designed to allow client devices to control 41 | media processing resources, such as speech recognition engines. MRCP4J 42 | provides a Java API that encapsulates the MRCPv2 protocol and can be 43 | used to implement MRCPv2 clients and/or servers. 44 | 45 | This release provides the same basic level of functional support as 46 | the previous release but has been more thoroughly tested. A number of 47 | issues found in the previous release have been addressed..." ({{{http://www.freelists.org/archives/speechforge-news/08-2006/msg00000.html}more}}) 48 | -------------------------------------------------------------------------------- /src/site/apt/install.apt: -------------------------------------------------------------------------------- 1 | ----- 2 | Installation 3 | ----- 4 | Niels Godfredsen 5 | ----- 6 | 7 | {Downloads} 8 | 9 | The latest version of MRCP4J can be downloaded {{{http://sourceforge.net/project/showfiles.php?group_id=143504}here}}. 10 | 11 | {Prerequisites} 12 | 13 | MRCP4J requires Java Runtime Environment (JRE) 5.0 or higher which can be downloaded {{{http://java.sun.com/javase/downloads/index.jsp}here}}. 14 | 15 | {Dependencies} 16 | 17 | MRCP4J has the following dependencies: 18 | 19 | *--------------------+-------------+------------------------------------------------------+ 20 | | | | | 21 | *--------------------+-------------+------------------------------------------------------+ 22 | | Commons Logging | 1.1 | {{http://jakarta.apache.org/commons/logging/}} | 23 | *--------------------+-------------+------------------------------------------------------+ 24 | | MINA | 0.8.0 | {{http://directory.apache.org/subprojects/network/}} | 25 | *--------------------+-------------+------------------------------------------------------+ 26 | | SLF4J | 1.0-beta9 | {{http://www.slf4j.org/}} | 27 | *--------------------+-------------+------------------------------------------------------+ 28 | 29 | Distribution jars for the above listed dependencies need to be included in your classpath in order to use MRCP4J. They are available for download from the provided URLs and are also included in the MRCP4J binary distribution. 30 | 31 | Note: The dependency versions listed above are as required for the latest release of MRCP4J. If you are using an earlier version of MRCP4J (or a pre-release snapshot build), please see the readme in the distribution for the required dependencies and versions. 32 | 33 | {Installation} 34 | 35 | To install MRCP4J extract the <<.jar>>> from the binary distribution archive and 36 | add it to your application's classpath along with the above listed dependencies. 37 | -------------------------------------------------------------------------------- /src/site/apt/intro.apt: -------------------------------------------------------------------------------- 1 | ----- 2 | Getting Started 3 | ----- 4 | Niels Godfredsen 5 | ----- 6 | 7 | Getting Started 8 | 9 | MRCP4J can be used for implementing both MRCPv2 clients as well as MRCPv2 servers. 10 | 11 | The following instructions assume you have already downloaded and installed the latest MRCP4J jar file. Instructions for downloading and installation can be found {{{install.html}here}}. 12 | 13 | Implementing an MRCPv2 {Client} 14 | 15 | The primary class for implementing MRCPv2 clients using MRCP4J is {{{docs/apidocs/org/mrcp4j/client/MrcpChannel.html}org.mrcp4j.client.MrcpChannel}}. All main client functions, such as sending requests to media resources and registering to listen for events from media resources, are available through this class. 16 | 17 | To construct a new MrcpChannel instance use {{{docs/apidocs/org/mrcp4j/client/MrcpProvider.html#createChannel(java.lang.String,%20java.net.InetAddress,%20int,%20java.lang.String)}MrcpProvider.createChannel()}}. 18 | 19 | For example: 20 | 21 | +-----------------------+ 22 | String channelID = "32AECB234338@speechrecog"; 23 | InetAddress host = InetAddress.getByName("server.example.com"); 24 | int port = 32416; 25 | String protocol = MrcpProvider.PROTOCOL_TCP_MRCPv2; // "TCP/MRCPv2" 26 | 27 | MrcpFactory factory = MrcpFactory.newInstance(); 28 | MrcpProvider provider = factory.createProvider(); 29 | MrcpChannel channel = provider.createChannel(channelID, host, port, protocol); 30 | 31 | MrcpRequest request = channel.createRequest(MrcpMethodName.RECOGNIZE); 32 | request.setContent("application/jsgf", null, grammarUrl); 33 | MrcpResponse response = channel.sendRequest(request); 34 | +-----------------------+ 35 | 36 | Note: If you are wondering where the channel ID and other parameters come from please see the {{{faq.html#WhyNoSipSupport}FAQ: Why doesn't MRCP4J provide facilities for establishing MRCPv2 sessions?}}. 37 | 38 | ~~MRCP4J does not provide facilities for establishing the media channels to the media 39 | 40 | 41 | 42 | Implementing an MRCPv2 {Server} 43 | 44 | TODOC 45 | -------------------------------------------------------------------------------- /src/site/fml/faq.fml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | What is MRCPv2? 6 | 7 |

8 | MRCPv2 stands for Media Resource Control Protocol Version 2 and is a protocol being developed by the Speech Services 9 | Control Working Group (Speechsc) 10 | of the Internet Engineering Task Force (IETF) to allow client hosts to 11 | control media processing resources such as speech synthesizers, speech recognizers, speaker 12 | verifiers and speaker identifiers residing in servers on the network. 13 |

14 |

15 | You can read the full text of the latest MRCPv2 draft here. 16 |

17 |
18 |
19 | 20 | Why doesn't MRCP4J provide facilities for establishing MRCPv2 sessions? 21 | 22 |

23 | Currently this functionality is beyond the scope of this project. Just as the MRCPv2 protocol relies on a session management 24 | protocol such as the Session Initiation Protocol (SIP) to establish the MRCPv2 control session between the client 25 | and the server, MRCP4J clients should make use of an appropriate SIP API implementation (such as 26 | JAIN-SIP) to supply this functionality. 27 |

28 |
29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /src/site/resources/images/mrcp4j-banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JVoiceXML/mrcp4j/90426ebb0cd1a495888324f964710947f66b43e6/src/site/resources/images/mrcp4j-banner.jpg -------------------------------------------------------------------------------- /src/site/resources/images/speechforge-banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JVoiceXML/mrcp4j/90426ebb0cd1a495888324f964710947f66b43e6/src/site/resources/images/speechforge-banner.jpg -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SpeechForge Banner 6 | images/speechforge-banner.jpg 7 | http://www.speechforge.org 8 | 9 | 10 | 11 | SourceForge.net Logo 12 | http://sflogo.sourceforge.net/sflogo.php?group_id=143504&type=5 13 | http://sourceforge.net/ 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 | -------------------------------------------------------------------------------- /src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %6r [%-20.20t] %-5p %30.30c (%6L) %x %m%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | --------------------------------------------------------------------------------