Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sound = component.sound
- -- Форманты гласных (сочетание частот для разных формант)
- local vowelFormants = {
- A = {F1 = 730, F2 = 1090, F3 = 2440},
- E = {F1 = 660, F2 = 1700, F3 = 2500},
- I = {F1 = 440, F2 = 2200, F3 = 2700},
- O = {F1 = 500, F2 = 1000, F3 = 2400},
- U = {F1 = 320, F2 = 880, F3 = 2240},
- }
- -- Настройки согласных
- local consonantSounds = {
- B = {freq = 300, wave = sound.modes.sine, duration = 100},
- C = {freq = 8000, wave = sound.modes.noise, duration = 80},
- D = {freq = 700, wave = sound.modes.sine, duration = 100},
- F = {freq = 7500, wave = sound.modes.noise, duration = 70},
- G = {freq = 400, wave = sound.modes.sine, duration = 100},
- H = {freq = 6000, wave = sound.modes.noise, duration = 80},
- L = {freq = 300, wave = sound.modes.sine, duration = 100},
- M = {freq = 300, wave = sound.modes.sine, duration = 120},
- N = {freq = 400, wave = sound.modes.sine, duration = 120},
- P = {freq = 4000, wave = sound.modes.sine, duration = 100},
- S = {freq = 8000, wave = sound.modes.noise, duration = 80},
- T = {freq = 7000, wave = sound.modes.noise, duration = 80},
- }
- -- Функция для гласных звуков
- local function playVowel(vowel)
- local formant = vowelFormants[vowel]
- if formant then
- -- F1
- sound.setFrequency(1, formant.F1)
- sound.setWave(1, sound.modes.sine)
- sound.setADSR(1, 0, 100, 200, 50)
- sound.open(1)
- -- F2
- sound.setFrequency(2, formant.F2)
- sound.setWave(2, sound.modes.triangle)
- sound.setADSR(2, 0, 100, 200, 50)
- sound.open(2)
- -- F3
- sound.setFrequency(3, formant.F3)
- sound.setWave(3, sound.modes.sine)
- sound.setADSR(3, 0, 100, 200, 50)
- sound.open(3)
- sound.delay(300) -- Гласные звучат дольше
- sound.close(1)
- sound.close(2)
- sound.close(3)
- sound.process()
- end
- end
- -- Функция для согласных звуков
- local function playConsonant(consonant)
- local soundConfig = consonantSounds[consonant]
- if soundConfig then
- sound.setFrequency(1, soundConfig.freq)
- sound.setWave(1, soundConfig.wave)
- sound.setADSR(1, 0, 50, 100, 50)
- sound.open(1)
- sound.delay(soundConfig.duration) -- Короче чем гласные
- sound.close(1)
- sound.process()
- end
- end
- -- Полный сброс каналов
- local function resetAllChannels()
- for i = 1, 4 do
- sound.close(i)
- end
- sound.process()
- end
- -- Основная функция синтеза речи
- local function synthesizeSpeech()
- while true do
- resetAllChannels() -- Полный сброс между словами
- print("Введите слово для синтеза (или 'exit' для выхода):")
- local input = io.read()
- if input == "exit" then
- break
- end
- for i = 1, #input do
- local letter = input:sub(i, i):upper()
- if vowelFormants[letter] then
- playVowel(letter)
- elseif consonantSounds[letter] then
- playConsonant(letter)
- else
- sound.delay(50) -- Пауза для пробелов или неизвестных букв
- end
- end
- end
- end
- -- Запуск программы
- synthesizeSpeech()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement