├── .gitignore ├── Cartfile ├── Cartfile.resolved ├── LICENSE ├── README.md ├── Speech to Text.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── Speech to Text ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── AudioFileViewController.swift ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── CredentialsExample.swift ├── Info.plist ├── MicrophoneAdvancedViewController.swift ├── MicrophoneBasicViewController.swift └── SpeechSample.wav /.gitignore: -------------------------------------------------------------------------------- 1 | # Custom 2 | Credentials.swift 3 | 4 | # Build generated 5 | build/ 6 | DerivedData/ 7 | 8 | # Various settings 9 | *.pbxuser 10 | !default.pbxuser 11 | *.mode1v3 12 | !default.mode1v3 13 | *.mode2v3 14 | !default.mode2v3 15 | *.perspectivev3 16 | !default.perspectivev3 17 | xcuserdata/ 18 | 19 | # Other 20 | .DS_Store 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | # Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | 28 | # Playgrounds 29 | timeline.xctimeline 30 | playground.xcworkspace 31 | 32 | # Swift Package Manager 33 | Packages/ 34 | .build/ 35 | 36 | # Carthage 37 | Carthage/ 38 | -------------------------------------------------------------------------------- /Cartfile: -------------------------------------------------------------------------------- 1 | github "watson-developer-cloud/swift-sdk" ~> 2.0.0 2 | -------------------------------------------------------------------------------- /Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "daltoniam/Starscream" "3.0.5" 2 | github "watson-developer-cloud/restkit" "3.0.1" 3 | github "watson-developer-cloud/swift-sdk" "2.0.2" 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Speech to Text Demo (Swift) 2 | 3 | This repository contains an example application to demonstrate how to use the Speech to Text functionality of the [Watson Developer Cloud Swift SDK](https://github.com/watson-developer-cloud/swift-sdk). 4 | 5 | ## Requirements 6 | 7 | - iOS 8.0+ 8 | - Xcode 9.0+ 9 | - Swift 4.0+ 10 | 11 | ## Dependency Management 12 | 13 | This project uses [Carthage](https://github.com/Carthage/Carthage) to manage dependencies. You can install Carthage using [Homebrew](http://brew.sh/). 14 | 15 | ``` 16 | > brew install carthage 17 | ``` 18 | 19 | ## Getting Started 20 | 21 | 1. Clone the repository: `git clone https://github.com/watson-developer-cloud/speech-to-text-swift.git` 22 | 2. Build the dependencies: `carthage update --platform iOS`. 23 | 3. Copy `CredentialsExample.swift` to `Credentials.swift`: `cp CredentialsExample.swift Credentials.swift` 24 | 4. Open `Speech to Text.xcodeproj` in Xcode 25 | 5. Update your Speech to Text instance's credentials in `Credentials.swift` 26 | 6. Build and run the app! 27 | -------------------------------------------------------------------------------- /Speech to Text.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0637D57021C9C594003A2924 /* RestKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0637D56F21C9C594003A2924 /* RestKit.framework */; }; 11 | 686F53331FFD1AFA008D3BA0 /* MicrophoneAdvancedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 686F53321FFD1AFA008D3BA0 /* MicrophoneAdvancedViewController.swift */; }; 12 | 68A4C5172016B39D00835EE4 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 68A4C5162016B39D00835EE4 /* Starscream.framework */; }; 13 | 7AE28FD31DD10D6900A663ED /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE28FD21DD10D6900A663ED /* AppDelegate.swift */; }; 14 | 7AE28FD51DD10D6900A663ED /* AudioFileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE28FD41DD10D6900A663ED /* AudioFileViewController.swift */; }; 15 | 7AE28FD81DD10D6900A663ED /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7AE28FD61DD10D6900A663ED /* Main.storyboard */; }; 16 | 7AE28FDA1DD10D6900A663ED /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7AE28FD91DD10D6900A663ED /* Assets.xcassets */; }; 17 | 7AE28FDD1DD10D6900A663ED /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7AE28FDB1DD10D6900A663ED /* LaunchScreen.storyboard */; }; 18 | 7AE28FE81DD1108500A663ED /* SpeechToTextV1.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7AE28FE61DD1108500A663ED /* SpeechToTextV1.framework */; }; 19 | 7AE28FEB1DD1214000A663ED /* SpeechSample.wav in Resources */ = {isa = PBXBuildFile; fileRef = 7AE28FEA1DD1214000A663ED /* SpeechSample.wav */; }; 20 | 7AE28FED1DD121CE00A663ED /* Credentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE28FEC1DD121CE00A663ED /* Credentials.swift */; }; 21 | 7AE28FEF1DD128D400A663ED /* MicrophoneBasicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE28FEE1DD128D400A663ED /* MicrophoneBasicViewController.swift */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 0637D56F21C9C594003A2924 /* RestKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RestKit.framework; path = Carthage/Build/iOS/RestKit.framework; sourceTree = ""; }; 26 | 686F53321FFD1AFA008D3BA0 /* MicrophoneAdvancedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MicrophoneAdvancedViewController.swift; sourceTree = ""; }; 27 | 68A4C5162016B39D00835EE4 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/iOS/Starscream.framework; sourceTree = ""; }; 28 | 7AE28FCF1DD10D6900A663ED /* Speech to Text.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Speech to Text.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | 7AE28FD21DD10D6900A663ED /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 30 | 7AE28FD41DD10D6900A663ED /* AudioFileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioFileViewController.swift; sourceTree = ""; }; 31 | 7AE28FD71DD10D6900A663ED /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 32 | 7AE28FD91DD10D6900A663ED /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 33 | 7AE28FDC1DD10D6900A663ED /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 34 | 7AE28FDE1DD10D6900A663ED /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 7AE28FE61DD1108500A663ED /* SpeechToTextV1.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SpeechToTextV1.framework; path = Carthage/Build/iOS/SpeechToTextV1.framework; sourceTree = ""; }; 36 | 7AE28FEA1DD1214000A663ED /* SpeechSample.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = SpeechSample.wav; sourceTree = ""; }; 37 | 7AE28FEC1DD121CE00A663ED /* Credentials.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Credentials.swift; sourceTree = ""; }; 38 | 7AE28FEE1DD128D400A663ED /* MicrophoneBasicViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MicrophoneBasicViewController.swift; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | 7AE28FCC1DD10D6900A663ED /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | 7AE28FE81DD1108500A663ED /* SpeechToTextV1.framework in Frameworks */, 47 | 68A4C5172016B39D00835EE4 /* Starscream.framework in Frameworks */, 48 | 0637D57021C9C594003A2924 /* RestKit.framework in Frameworks */, 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | 7AE28FC61DD10D6900A663ED = { 56 | isa = PBXGroup; 57 | children = ( 58 | 7AE28FD11DD10D6900A663ED /* Speech to Text */, 59 | 7AE28FD01DD10D6900A663ED /* Products */, 60 | 7AE28FE41DD1108500A663ED /* Frameworks */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | 7AE28FD01DD10D6900A663ED /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 7AE28FCF1DD10D6900A663ED /* Speech to Text.app */, 68 | ); 69 | name = Products; 70 | sourceTree = ""; 71 | }; 72 | 7AE28FD11DD10D6900A663ED /* Speech to Text */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 7AE28FD21DD10D6900A663ED /* AppDelegate.swift */, 76 | 7AE28FD91DD10D6900A663ED /* Assets.xcassets */, 77 | 7AE28FD41DD10D6900A663ED /* AudioFileViewController.swift */, 78 | 7AE28FEC1DD121CE00A663ED /* Credentials.swift */, 79 | 7AE28FDE1DD10D6900A663ED /* Info.plist */, 80 | 7AE28FDB1DD10D6900A663ED /* LaunchScreen.storyboard */, 81 | 7AE28FD61DD10D6900A663ED /* Main.storyboard */, 82 | 7AE28FEA1DD1214000A663ED /* SpeechSample.wav */, 83 | 7AE28FEE1DD128D400A663ED /* MicrophoneBasicViewController.swift */, 84 | 686F53321FFD1AFA008D3BA0 /* MicrophoneAdvancedViewController.swift */, 85 | ); 86 | path = "Speech to Text"; 87 | sourceTree = ""; 88 | }; 89 | 7AE28FE41DD1108500A663ED /* Frameworks */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 0637D56F21C9C594003A2924 /* RestKit.framework */, 93 | 68A4C5162016B39D00835EE4 /* Starscream.framework */, 94 | 7AE28FE61DD1108500A663ED /* SpeechToTextV1.framework */, 95 | ); 96 | name = Frameworks; 97 | sourceTree = ""; 98 | }; 99 | /* End PBXGroup section */ 100 | 101 | /* Begin PBXNativeTarget section */ 102 | 7AE28FCE1DD10D6900A663ED /* Speech to Text */ = { 103 | isa = PBXNativeTarget; 104 | buildConfigurationList = 7AE28FE11DD10D6900A663ED /* Build configuration list for PBXNativeTarget "Speech to Text" */; 105 | buildPhases = ( 106 | 7AE28FCB1DD10D6900A663ED /* Sources */, 107 | 7AE28FCC1DD10D6900A663ED /* Frameworks */, 108 | 7AE28FCD1DD10D6900A663ED /* Resources */, 109 | 7AE28FE91DD1108F00A663ED /* ShellScript */, 110 | ); 111 | buildRules = ( 112 | ); 113 | dependencies = ( 114 | ); 115 | name = "Speech to Text"; 116 | productName = "Speech to Text"; 117 | productReference = 7AE28FCF1DD10D6900A663ED /* Speech to Text.app */; 118 | productType = "com.apple.product-type.application"; 119 | }; 120 | /* End PBXNativeTarget section */ 121 | 122 | /* Begin PBXProject section */ 123 | 7AE28FC71DD10D6900A663ED /* Project object */ = { 124 | isa = PBXProject; 125 | attributes = { 126 | LastSwiftUpdateCheck = 0800; 127 | LastUpgradeCheck = 0900; 128 | ORGANIZATIONNAME = "IBM Watson Developer Cloud"; 129 | TargetAttributes = { 130 | 7AE28FCE1DD10D6900A663ED = { 131 | CreatedOnToolsVersion = 8.0; 132 | ProvisioningStyle = Automatic; 133 | }; 134 | }; 135 | }; 136 | buildConfigurationList = 7AE28FCA1DD10D6900A663ED /* Build configuration list for PBXProject "Speech to Text" */; 137 | compatibilityVersion = "Xcode 3.2"; 138 | developmentRegion = English; 139 | hasScannedForEncodings = 0; 140 | knownRegions = ( 141 | en, 142 | Base, 143 | ); 144 | mainGroup = 7AE28FC61DD10D6900A663ED; 145 | productRefGroup = 7AE28FD01DD10D6900A663ED /* Products */; 146 | projectDirPath = ""; 147 | projectRoot = ""; 148 | targets = ( 149 | 7AE28FCE1DD10D6900A663ED /* Speech to Text */, 150 | ); 151 | }; 152 | /* End PBXProject section */ 153 | 154 | /* Begin PBXResourcesBuildPhase section */ 155 | 7AE28FCD1DD10D6900A663ED /* Resources */ = { 156 | isa = PBXResourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | 7AE28FDD1DD10D6900A663ED /* LaunchScreen.storyboard in Resources */, 160 | 7AE28FDA1DD10D6900A663ED /* Assets.xcassets in Resources */, 161 | 7AE28FEB1DD1214000A663ED /* SpeechSample.wav in Resources */, 162 | 7AE28FD81DD10D6900A663ED /* Main.storyboard in Resources */, 163 | ); 164 | runOnlyForDeploymentPostprocessing = 0; 165 | }; 166 | /* End PBXResourcesBuildPhase section */ 167 | 168 | /* Begin PBXShellScriptBuildPhase section */ 169 | 7AE28FE91DD1108F00A663ED /* ShellScript */ = { 170 | isa = PBXShellScriptBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | ); 174 | inputPaths = ( 175 | "$(SRCROOT)/Carthage/Build/iOS/SpeechToTextV1.framework", 176 | "$(SRCROOT)/Carthage/Build/iOS/Starscream.framework", 177 | "$(SRCROOT)/Carthage/Build/iOS/RestKit.framework", 178 | ); 179 | outputPaths = ( 180 | ); 181 | runOnlyForDeploymentPostprocessing = 0; 182 | shellPath = /bin/sh; 183 | shellScript = "/usr/local/bin/carthage copy-frameworks\n"; 184 | }; 185 | /* End PBXShellScriptBuildPhase section */ 186 | 187 | /* Begin PBXSourcesBuildPhase section */ 188 | 7AE28FCB1DD10D6900A663ED /* Sources */ = { 189 | isa = PBXSourcesBuildPhase; 190 | buildActionMask = 2147483647; 191 | files = ( 192 | 7AE28FEF1DD128D400A663ED /* MicrophoneBasicViewController.swift in Sources */, 193 | 7AE28FED1DD121CE00A663ED /* Credentials.swift in Sources */, 194 | 7AE28FD51DD10D6900A663ED /* AudioFileViewController.swift in Sources */, 195 | 7AE28FD31DD10D6900A663ED /* AppDelegate.swift in Sources */, 196 | 686F53331FFD1AFA008D3BA0 /* MicrophoneAdvancedViewController.swift in Sources */, 197 | ); 198 | runOnlyForDeploymentPostprocessing = 0; 199 | }; 200 | /* End PBXSourcesBuildPhase section */ 201 | 202 | /* Begin PBXVariantGroup section */ 203 | 7AE28FD61DD10D6900A663ED /* Main.storyboard */ = { 204 | isa = PBXVariantGroup; 205 | children = ( 206 | 7AE28FD71DD10D6900A663ED /* Base */, 207 | ); 208 | name = Main.storyboard; 209 | sourceTree = ""; 210 | }; 211 | 7AE28FDB1DD10D6900A663ED /* LaunchScreen.storyboard */ = { 212 | isa = PBXVariantGroup; 213 | children = ( 214 | 7AE28FDC1DD10D6900A663ED /* Base */, 215 | ); 216 | name = LaunchScreen.storyboard; 217 | sourceTree = ""; 218 | }; 219 | /* End PBXVariantGroup section */ 220 | 221 | /* Begin XCBuildConfiguration section */ 222 | 7AE28FDF1DD10D6900A663ED /* Debug */ = { 223 | isa = XCBuildConfiguration; 224 | buildSettings = { 225 | ALWAYS_SEARCH_USER_PATHS = NO; 226 | CLANG_ANALYZER_NONNULL = YES; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_MODULES = YES; 230 | CLANG_ENABLE_OBJC_ARC = YES; 231 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 232 | CLANG_WARN_BOOL_CONVERSION = YES; 233 | CLANG_WARN_COMMA = YES; 234 | CLANG_WARN_CONSTANT_CONVERSION = YES; 235 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 236 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 237 | CLANG_WARN_EMPTY_BODY = YES; 238 | CLANG_WARN_ENUM_CONVERSION = YES; 239 | CLANG_WARN_INFINITE_RECURSION = YES; 240 | CLANG_WARN_INT_CONVERSION = YES; 241 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 242 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 243 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 244 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 245 | CLANG_WARN_STRICT_PROTOTYPES = YES; 246 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 247 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 248 | CLANG_WARN_UNREACHABLE_CODE = YES; 249 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 250 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 251 | COPY_PHASE_STRIP = NO; 252 | DEBUG_INFORMATION_FORMAT = dwarf; 253 | ENABLE_STRICT_OBJC_MSGSEND = YES; 254 | ENABLE_TESTABILITY = YES; 255 | GCC_C_LANGUAGE_STANDARD = gnu99; 256 | GCC_DYNAMIC_NO_PIC = NO; 257 | GCC_NO_COMMON_BLOCKS = YES; 258 | GCC_OPTIMIZATION_LEVEL = 0; 259 | GCC_PREPROCESSOR_DEFINITIONS = ( 260 | "DEBUG=1", 261 | "$(inherited)", 262 | ); 263 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 264 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 265 | GCC_WARN_UNDECLARED_SELECTOR = YES; 266 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 267 | GCC_WARN_UNUSED_FUNCTION = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 270 | MTL_ENABLE_DEBUG_INFO = YES; 271 | ONLY_ACTIVE_ARCH = YES; 272 | SDKROOT = iphoneos; 273 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 274 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 275 | SWIFT_VERSION = 4.0; 276 | TARGETED_DEVICE_FAMILY = "1,2"; 277 | }; 278 | name = Debug; 279 | }; 280 | 7AE28FE01DD10D6900A663ED /* Release */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | ALWAYS_SEARCH_USER_PATHS = NO; 284 | CLANG_ANALYZER_NONNULL = YES; 285 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 286 | CLANG_CXX_LIBRARY = "libc++"; 287 | CLANG_ENABLE_MODULES = YES; 288 | CLANG_ENABLE_OBJC_ARC = YES; 289 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 290 | CLANG_WARN_BOOL_CONVERSION = YES; 291 | CLANG_WARN_COMMA = YES; 292 | CLANG_WARN_CONSTANT_CONVERSION = YES; 293 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 294 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 295 | CLANG_WARN_EMPTY_BODY = YES; 296 | CLANG_WARN_ENUM_CONVERSION = YES; 297 | CLANG_WARN_INFINITE_RECURSION = YES; 298 | CLANG_WARN_INT_CONVERSION = YES; 299 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 300 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 301 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 302 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 303 | CLANG_WARN_STRICT_PROTOTYPES = YES; 304 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 305 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 306 | CLANG_WARN_UNREACHABLE_CODE = YES; 307 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 308 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 309 | COPY_PHASE_STRIP = NO; 310 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 311 | ENABLE_NS_ASSERTIONS = NO; 312 | ENABLE_STRICT_OBJC_MSGSEND = YES; 313 | GCC_C_LANGUAGE_STANDARD = gnu99; 314 | GCC_NO_COMMON_BLOCKS = YES; 315 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 316 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 317 | GCC_WARN_UNDECLARED_SELECTOR = YES; 318 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 319 | GCC_WARN_UNUSED_FUNCTION = YES; 320 | GCC_WARN_UNUSED_VARIABLE = YES; 321 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 322 | MTL_ENABLE_DEBUG_INFO = NO; 323 | SDKROOT = iphoneos; 324 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 325 | SWIFT_VERSION = 4.0; 326 | TARGETED_DEVICE_FAMILY = "1,2"; 327 | VALIDATE_PRODUCT = YES; 328 | }; 329 | name = Release; 330 | }; 331 | 7AE28FE21DD10D6900A663ED /* Debug */ = { 332 | isa = XCBuildConfiguration; 333 | buildSettings = { 334 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 335 | FRAMEWORK_SEARCH_PATHS = ( 336 | "$(inherited)", 337 | "$(PROJECT_DIR)/Carthage/Build/iOS", 338 | ); 339 | INFOPLIST_FILE = "Speech to Text/Info.plist"; 340 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 341 | PRODUCT_BUNDLE_IDENTIFIER = "com.ibm.watson.developer-cloud.Speech-to-Text"; 342 | PRODUCT_NAME = "$(TARGET_NAME)"; 343 | SWIFT_VERSION = 4.0; 344 | }; 345 | name = Debug; 346 | }; 347 | 7AE28FE31DD10D6900A663ED /* Release */ = { 348 | isa = XCBuildConfiguration; 349 | buildSettings = { 350 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 351 | FRAMEWORK_SEARCH_PATHS = ( 352 | "$(inherited)", 353 | "$(PROJECT_DIR)/Carthage/Build/iOS", 354 | ); 355 | INFOPLIST_FILE = "Speech to Text/Info.plist"; 356 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 357 | PRODUCT_BUNDLE_IDENTIFIER = "com.ibm.watson.developer-cloud.Speech-to-Text"; 358 | PRODUCT_NAME = "$(TARGET_NAME)"; 359 | SWIFT_VERSION = 4.0; 360 | }; 361 | name = Release; 362 | }; 363 | /* End XCBuildConfiguration section */ 364 | 365 | /* Begin XCConfigurationList section */ 366 | 7AE28FCA1DD10D6900A663ED /* Build configuration list for PBXProject "Speech to Text" */ = { 367 | isa = XCConfigurationList; 368 | buildConfigurations = ( 369 | 7AE28FDF1DD10D6900A663ED /* Debug */, 370 | 7AE28FE01DD10D6900A663ED /* Release */, 371 | ); 372 | defaultConfigurationIsVisible = 0; 373 | defaultConfigurationName = Release; 374 | }; 375 | 7AE28FE11DD10D6900A663ED /* Build configuration list for PBXNativeTarget "Speech to Text" */ = { 376 | isa = XCConfigurationList; 377 | buildConfigurations = ( 378 | 7AE28FE21DD10D6900A663ED /* Debug */, 379 | 7AE28FE31DD10D6900A663ED /* Release */, 380 | ); 381 | defaultConfigurationIsVisible = 0; 382 | defaultConfigurationName = Release; 383 | }; 384 | /* End XCConfigurationList section */ 385 | }; 386 | rootObject = 7AE28FC71DD10D6900A663ED /* Project object */; 387 | } 388 | -------------------------------------------------------------------------------- /Speech to Text.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Speech to Text/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright IBM Corporation 2016 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | 17 | import UIKit 18 | 19 | @UIApplicationMain 20 | class AppDelegate: UIResponder, UIApplicationDelegate { 21 | 22 | var window: UIWindow? 23 | 24 | 25 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 26 | // Override point for customization after application launch. 27 | return true 28 | } 29 | 30 | func applicationWillResignActive(_ application: UIApplication) { 31 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 32 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 33 | } 34 | 35 | func applicationDidEnterBackground(_ application: UIApplication) { 36 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | func applicationWillEnterForeground(_ application: UIApplication) { 41 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 42 | } 43 | 44 | func applicationDidBecomeActive(_ application: UIApplication) { 45 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 46 | } 47 | 48 | func applicationWillTerminate(_ application: UIApplication) { 49 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 50 | } 51 | 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Speech to Text/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Speech to Text/AudioFileViewController.swift: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright IBM Corporation 2016 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | 17 | import UIKit 18 | import AVFoundation 19 | import SpeechToTextV1 20 | 21 | class AudioFileViewController: UIViewController, AVAudioPlayerDelegate { 22 | 23 | var player: AVAudioPlayer! 24 | var speechToText: SpeechToText! 25 | var speechSample: URL! 26 | var accumulator = SpeechRecognitionResultsAccumulator() 27 | 28 | @IBOutlet weak var playButton: UIButton! 29 | @IBOutlet weak var textView: UITextView! 30 | 31 | override func viewDidLoad() { 32 | super.viewDidLoad() 33 | speechSample = Bundle.main.url(forResource: "SpeechSample", withExtension: "wav") 34 | player = try! AVAudioPlayer(contentsOf: speechSample) 35 | speechToText = SpeechToText( 36 | apiKey: Credentials.SpeechToTextApiKey 37 | ) 38 | player.delegate = self 39 | } 40 | 41 | func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) { 42 | playButton.setTitle("Play Audio File", for: .normal) 43 | } 44 | 45 | @IBAction func didPressPlayButton(_ sender: UIButton) { 46 | if !player.isPlaying { 47 | playButton.setTitle("Stop Audio File", for: .normal) 48 | player.currentTime = 0 49 | player.play() 50 | } else { 51 | playButton.setTitle("Play Audio File", for: .normal) 52 | player.stop() 53 | } 54 | } 55 | 56 | @IBAction func didPressTranscribeButton(_ sender: UIButton) { 57 | let audio = try! Data(contentsOf: speechSample) 58 | var settings = RecognitionSettings(contentType: "audio/wav") 59 | settings.interimResults = true 60 | var callback = RecognizeCallback() 61 | callback.onError = { error in 62 | print(error) 63 | } 64 | callback.onResults = { results in 65 | self.accumulator.add(results: results) 66 | print(self.accumulator.bestTranscript) 67 | self.textView.text = self.accumulator.bestTranscript 68 | } 69 | speechToText.recognizeUsingWebSocket(audio: audio, settings: settings, callback: callback) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Speech to Text/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /Speech to Text/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | 34 | 41 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 187 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | -------------------------------------------------------------------------------- /Speech to Text/CredentialsExample.swift: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright IBM Corporation 2016 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | 17 | struct Credentials { 18 | static let SpeechToTextApiKey = "your-apikey-here" 19 | } 20 | -------------------------------------------------------------------------------- /Speech to Text/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSMicrophoneUsageDescription 24 | Microphone audio is transcribed by the Speech to Text service. 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Speech to Text/MicrophoneAdvancedViewController.swift: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright IBM Corporation 2018 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | 17 | import UIKit 18 | import AVFoundation 19 | import SpeechToTextV1 20 | 21 | /// This file demonstrates an advanced configuration using the `SpeechToTextSession` class. 22 | class MicrophoneAdvancedViewController: UIViewController { 23 | 24 | var session: SpeechToTextSession! 25 | var settings: RecognitionSettings! 26 | var isSessionStarted = false 27 | var isStreaming = false 28 | var accumulator = SpeechRecognitionResultsAccumulator() 29 | 30 | @IBOutlet weak var sessionButton: UIButton! 31 | @IBOutlet weak var microphoneButton: UIButton! 32 | @IBOutlet weak var textView: UITextView! 33 | 34 | 35 | override func viewDidLoad() { 36 | super.viewDidLoad() 37 | 38 | // use `SpeechToTextSession` for advanced configuration 39 | session = SpeechToTextSession( 40 | apiKey: Credentials.SpeechToTextApiKey 41 | ) 42 | 43 | // define recognition session callbacks 44 | session.onConnect = { print("connected") } 45 | session.onDisconnect = { print("disconnected") } 46 | session.onError = { error in print(error) } 47 | session.onPowerData = { decibels in print(decibels) } 48 | session.onMicrophoneData = { data in print("received data") } 49 | session.onResults = { 50 | results in 51 | self.accumulator.add(results: results) 52 | self.textView.text = self.accumulator.bestTranscript 53 | } 54 | 55 | // define recognition settings 56 | settings = RecognitionSettings(contentType: "audio/ogg;codecs=opus") 57 | settings.interimResults = true 58 | settings.inactivityTimeout = -1 59 | 60 | // request microphone permission 61 | requestMicrophonePermission() 62 | 63 | // configure audio session 64 | configureAudioSession() 65 | } 66 | 67 | /// The `SpeechToTextSession` class will automatically request access to the microphone when 68 | /// it is needed. But some apps may prefer to request microphone permission in advance. 69 | func requestMicrophonePermission() { 70 | AVCaptureDevice.requestAccess(for: .audio) { granted in 71 | print("audio capture permission granted: \(granted)") 72 | } 73 | } 74 | 75 | /// Depending on your application's requirements, you might need to configure the default 76 | /// audio session to play nicely with other audio sources. For example, this function 77 | /// configures the session to default to the speaker (instead of headphones) and mix 78 | /// with audio from other apps rather than stopping playback when recording starts. 79 | func configureAudioSession() { 80 | do { 81 | let audioSession = AVAudioSession.sharedInstance() 82 | try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: [.defaultToSpeaker, .mixWithOthers]) 83 | try audioSession.setActive(true) 84 | } catch { 85 | print("Failed to setup the AVAudioSession.") 86 | } 87 | } 88 | 89 | @IBAction func didPressSessionButton(_ sender: UIButton) { 90 | if !isSessionStarted { 91 | isSessionStarted = true 92 | sessionButton.setTitle("Stop Session", for: .normal) 93 | session.connect() 94 | session.startRequest(settings: settings) 95 | } else { 96 | isSessionStarted = false 97 | isStreaming = false 98 | sessionButton.setTitle("Start Sesson", for: .normal) 99 | microphoneButton.setTitle("Start Microphone", for: .normal) 100 | session.stopMicrophone() 101 | session.stopRequest() 102 | session.disconnect() 103 | } 104 | } 105 | 106 | @IBAction func didPressMicrophoneButton(_ sender: UIButton) { 107 | if !isStreaming && isSessionStarted { 108 | isStreaming = true 109 | microphoneButton.setTitle("Stop Microphone", for: .normal) 110 | session.startMicrophone() 111 | } else { 112 | isStreaming = false 113 | microphoneButton.setTitle("Start Microphone", for: .normal) 114 | session.stopMicrophone() 115 | } 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /Speech to Text/MicrophoneBasicViewController.swift: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright IBM Corporation 2016, 2018 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | 17 | import UIKit 18 | import SpeechToTextV1 19 | 20 | class MicrophoneBasicViewController: UIViewController { 21 | 22 | var speechToText: SpeechToText! 23 | var isStreaming = false 24 | var accumulator = SpeechRecognitionResultsAccumulator() 25 | 26 | @IBOutlet weak var microphoneButton: UIButton! 27 | @IBOutlet weak var textView: UITextView! 28 | 29 | override func viewDidLoad() { 30 | super.viewDidLoad() 31 | speechToText = SpeechToText( 32 | apiKey: Credentials.SpeechToTextApiKey 33 | ) 34 | } 35 | 36 | @IBAction func didPressMicrophoneButton(_ sender: UIButton) { 37 | if !isStreaming { 38 | isStreaming = true 39 | microphoneButton.setTitle("Stop Microphone", for: .normal) 40 | var settings = RecognitionSettings(contentType: "audio/ogg;codecs=opus") 41 | settings.interimResults = true 42 | var callback = RecognizeCallback() 43 | callback.onError = { error in 44 | print(error) 45 | } 46 | callback.onResults = { results in 47 | self.accumulator.add(results: results) 48 | print(self.accumulator.bestTranscript) 49 | self.textView.text = self.accumulator.bestTranscript 50 | } 51 | 52 | speechToText.recognizeMicrophone(settings: settings, callback: callback) 53 | } else { 54 | isStreaming = false 55 | microphoneButton.setTitle("Start Microphone", for: .normal) 56 | speechToText.stopRecognizeMicrophone() 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Speech to Text/SpeechSample.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watson-developer-cloud/speech-to-text-swift/10a0dba8cc73216ac79bd28c6247ec5c95090b3c/Speech to Text/SpeechSample.wav --------------------------------------------------------------------------------