下面是相关的代码:不能下标类型的值“[Int16类型]”
/// Individual audio samples
let samples: [Int16]
/// The rates in Hz
let sampleRate: Int
/// The part of the audio which is a vowel utterance
lazy var vowelPart: Range<Int> = {
let strongPart = SpeechAnalyzer2.findStrongPartOfSignal(self.samples, withChunks: 300, sensitivity: 0.1)
let clippedPart = SpeechAnalyzer2.truncateTailsOfRange(strongPart, portion: 0.15)
return clippedPart
}()
private lazy var vowelSamplesDecimated: [Int16] = {
let out = SpeechAnalyzer2.decimateSamples(self.samples[self.vowelPart], withFactor: 4)
return out
}()
的out = ...
线在底部给出了错误:
cannot subscript a value of type '[Int16]'
首先,如何是这样的错误信息甚至是有效的(当然你可以下标一个数组!)。其次,我该如何解决这个问题呢?
更新,接受Nate的回答后,这里是我如何更新下游功能是通用的CollectionType
以供将来参考:
/// Select the first of every `factor` items from `samples`
class func decimateSamples<T: CollectionType where T.Index: Strideable>(samples: T, withStride stride: T.Index.Stride) -> Array<T.Generator.Element> {
let selectedSamples = samples.startIndex.stride(to: samples.endIndex, by: stride)
return selectedSamples.map({samples[$0]})
}
什么是完整的错误信息?通常在'can not subscript'后面有' – Cristik
'类型的索引,我昨天发生了类似的错误,我认为它可能与你传递的函数有关。 –
@Cristik这是*整个*错误信息,这就是我的要求 –