AVSpeechUtterance Not Working - ios8

In IOS 8 AVSpeechUtterance is Not Working. Every time I use AVSpeechSynthesizer along with AVSpeechUtterance, I get "Speech initialization error: 2147483665". The same code works fine for IOS 7.1 I have a very large text to convert to speech, and using Google TTS won't allow me to use more than 100 characters at a time. How can I implement text-to-speech in IOS 8? Any help will be appreciated.

See this topic, and linked question also: AVSpeechSynthesizer iOS 8 Issues
For me, TTS on iOS work only on real device, not simulator. But iOS8 still have some problems with voices, some workaround mentioned in questions above.
Also, please mention this (user should set some settings): Using AVSpeechSynthesizer/AVSpeechUtterance for Text-To-Speech will not work if SpeakSelection is not enabled in device's Accessiblity settings

First import Speech
import Speech
Secondly define global variable for AVSpeechSynthesizer
let speakTalk = AVSpeechSynthesizer()
Create function Audio to take input as string
func Audio(Input : String)
{
let speakText = AVSpeechUtterance(string: "\(Input)")
speakText.rate = 0.5
speakText.pitchMultiplier = 1.7
speakTalk.speak(speakText)
}
call func Audio()
Audio(Input : "Hello")

Related

Swift: using NSRunningApplication

I'm trying to activate a running application, but can't seem to get the app.activateWithOptions call correct as each of the four attempts below result in compile time errors.
import AppKit
var ws = NSWorkspace.sharedWorkspace()
var apps = ws.runningApplications
var app :NSRunningApplication
for app in apps {
if (app.activationPolicy == NSApplicationActivationPolicy.Regular) {
app.activateWithOptions(options: ActivateIgnoringOtherApps)
app.activateWithOptions(options: NSApplicationActivateIgnoringOtherApps)
app.activateWithOptions(options: NSRunningApplication.ActivateIgnoringOtherApps)
app.activateWithOptions(options: NSRunningApplication.NSApplicationActivateIgnoringOtherApps)
println(app.localizedName)
}
}
The declaration var app : NSRunningApplication is pointless, because the app in the for...in line declares a different app. You should just delete that line, as it is misleading you and is utterly pointless and confusing.
Thus, it is that app, the one in the for...in that you need to specify the type of. You won't get any further in this attempt to compile until you fix that:
for app in apps as [NSRunningApplication] {
Now you can begin to fix your errors, one by one. I'll just give you a hint for the first one; it should be:
app.activateWithOptions(.ActivateIgnoringOtherApps)
The remaining three lines are left as an exercise for the reader! Even then you will still be in some trouble, though, because you are not combining the options - instead, you are activating the same app four separate times, which is silly and not at all what you want. You should combine the options first and then active the app once.
On the whole, it looks from your code as if you do not know Swift at all. You really should stop and learn it before you try to use it. Otherwise you'll just be flailing (as you clearly are now).
Thanks for the answer Matt. I'll add that if you are looking for just your application (rather than you can add a line before activating it. The following two lines will assign your application to the constant "app" and then activates it. This is useful for when yo want to get an NSAlert on the screen from an app running in the background.
let app = NSRunningApplication.currentApplication()
app.activateWithOptions(.ActivateIgnoringOtherApps)
let user_choice = alert.runModal()

Array and Dictionary type declarations in Swift

According to my understanding of the documentation, this should be correct:
var cookies: [NSHTTPCookie] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as [NSHTTPCookie]
where I'm creating an array of NSHTTPCookie objects. The interpreter does not like this syntax, however, giving me "Expected type after 'as'" and putting a little pointer at the opening bracket of the [NSHTTPCookie] at the end.
However, this works:
var cookies:NSHTTPCookie[] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as NSHTTPCookie[]
From the documentation, it seems like the first version is more correct, however.
Here's another example, this time with someone else's code. No one else using this code has reported the same behavior I get. (This is just a snippet; if the context is relevant let me know and I'll post more)
func asDict(x: AnyObject) -> [String:AnyObject]? {
return x as? [String:AnyObject]
}
In this case the playground interpreter objects in both places [String:AnyObject] is used. It just doesn't seem to be recognizing it as a type.
I double-checked to make sure I have the most recent beta of Xcode 6, but it seems much more likely to me that the problem is in my understanding rather than in the tool, since this would be a mighty big bug for only me to experience.
You must be using an old beta, this works in Beta 5 playground:
import Foundation
println("hello")
var cookies:[NSHTTPCookie] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as [NSHTTPCookie]
println("goodbye")

Int32 can't be converted to gcl_queue_flags

My attempt to use OpenCL with the Swift language (using xcode6 Dp4, Yosemite DP4) fails:
import Cocoa
import OpenCL
-
-
var queue: dispatch_queue_t = gcl_create_dispatch_queue(CL_DEVICE_TYPE_GPU, nil)
-
-
An error message comes up at "var queue ..."-line; "Int32 can't be converted to gcl_queue_flags". The line of code works perfectly when using Objective-C or C. Testing OpenCL (and GCDas well) seems not work in playground.
This is an issue with the way the CL_DEVICE_TYPE_GPU macro is imported to Swift — it's an Int32, but the function takes UInt64. So you can use cl_queue_flags(CL_DEVICE_TYPE_GPU) to convert it. You might also want to file a bug.

Swift NSDate Xcode error - SourceKitService terminated

import Foundation
var currentTime = NSDate()
println("It is currently", currentTime)
This Swift code is very simple and should work, correct? Why am i receiving an error that says "SourceKitService terminated - editor functionality currently limited"
Am I doing something wrong or is it the beta's fault?
You would use string interpolation as Jack Wu suggested in the first comment:
println("It is currently \(currentTime)")
The println primary function does not take multiple arguments. You could also use
println(currentTime)
However, the fact that your first (syntax error) attempt causes Xcode 6 to crash (at least it does for me) is certainly a bug. You should just get an issue reported.

WIA, Vista, and VB6. Does this code work?

Basically the constraints here are that i must use WIA because i am trying to get my scanner software to work in Windows 7 and Vista. It would be preferable (like really preferable) if i could do this in VB6.
Now this code i have compiles and everything, however when i run it i get the error "No WIA device of the selected type is available." I'm beginning to suspect that my scanner is not WIA compatible.
Could anyone confirm that this code should work? (needs to work with any WIA device not just scanners)
Dim WIADia As WIA.CommonDialog
Dim Scan As WIA.DeviceManager
Set WIADia = New WIA.CommonDialog
Set Scan = WIADia.ShowSelectDevice(WIA.WiaDeviceType.UnspecifiedDeviceType, True, False)
WIADia.ShowAcquisitionWizard (Scan)
Thanks!
WIA.CommonDialog WIADia;
Device Scan;
WIADia = new WIA.CommonDialog();
Scan = WIADia.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);
WIADia.ShowAcquisitionWizard(Scan);

Resources