-
Notifications
You must be signed in to change notification settings - Fork 124
/
speech_to_phonemes.swift
51 lines (42 loc) · 1.69 KB
/
speech_to_phonemes.swift
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import AppKit
// me:~$ say Adamic
// me:~$ say Adamec
var tts=NSSpeechSynthesizer.init(voice:"com.apple.speech.synthesis.voice.Vicki")
var text="Hallo"
for s in Process.arguments {
text=s
}
extension NSString {
func split(pattern: String) -> [AnyObject] {return self.componentsSeparatedByString(pattern); }
var strip:String { return self.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())}
func replace(pattern: String,with:String)->String{return self.stringByReplacingOccurrencesOfString(pattern,withString:with);}
}
// tts.delegate=MyDelegate()
// tts.startSpeakingString("Hallo")
println(tts.phonemesFromText(text))
var path="/Users/me/data/base/lang/english.index"
let content = NSString(contentsOfFile:path, encoding: NSUTF8StringEncoding, error: nil) as String
var all=content.split("\n")
// let content = NSArray(contentsOfFile:path)
for obj: AnyObject in all {
var word=obj as String
var phoneme=tts.phonemesFromText(word).replace(" ~",with:"~") as String
// if var rawStandard = obj as? NSDictionary {
// println(obj)
println(word.strip+"\t"+phoneme)
}
// println(content)
// cat ~/data/base/words/english.index| while read w;do echo "$w"; say "$w" -o "spoken_words/$w.m4a";done
// @objc class MyDelegate : NSObject,NSSpeechSynthesizerDelegate{// ,NSObjectProtocol
// // override _ sender:
// func speechSynthesizer(sender: NSSpeechSynthesizer, willSpeakPhoneme phoneme: Int16){
// print("Doesn't fucking work why not")
// }
// func run(){
// var tts=NSSpeechSynthesizer.init(voice:"com.apple.speech.synthesis.voice.Vicki")
// tts.delegate=self
// tts.startSpeakingString(text)
// }
// }
// MyDelegate().run()
// sleep(2);