摩斯代码在线html,HTML5 摩斯(Morse)电码生成器

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

'use strict';

var MorseCode = function MorseCode() {

this.DOT = 'dot';

this.DASH = 'dash';

this.SPACE = 'space';

this.map = {

'a': [

this.DOT,

this.DASH

],

'b': [

this.DASH,

this.DOT,

this.DOT,

this.DOT

],

'c': [

this.DASH,

this.DOT,

this.DASH,

this.DOT

],

'd': [

this.DASH,

this.DOT,

this.DOT

],

'e': [this.DOT],

'f': [

this.DOT,

this.DOT,

this.DASH,

this.DOT

],

'g': [

this.DASH,

this.DASH,

this.DAT

],

'h': [

this.DOT,

this.DOT,

this.DOT,

this.DOT

],

'i': [

this.DOT,

this.DOT

],

'j': [

this.DOT,

this.DASH,

this.DASH,

this.DASH

],

'k': [

this.DASH,

this.DOT,

this.DASH

],

'l': [

this.DOT,

this.DASH,

this.DOT,

this.DOT

],

'm': [

this.DASH,

this.DASH

],

'n': [

this.DASH,

this.DOT

],

'o': [

this.DASH,

this.DASH,

this.DASH

],

'p': [

this.DOT,

this.DASH,

this.DASH,

this.DOT

],

'q': [

this.DASH,

this.DASH,

this.DOT,

this.DASH

],

'r': [

this.DOT,

this.DASH,

this.DOT

],

's': [

this.DOT,

this.DOT,

this.DOT

],

't': [this.DASH],

'u': [

this.DOT,

this.DOT,

this.DASH,

this.DASH

],

'v': [

this.DOT,

this.DOT,

this.DOT,

this.DASH

],

'w': [

this.DOT,

this.DASH,

this.DASH

],

'x': [

this.DASH,

this.DOT,

this.DOT,

this.DASH

],

'y': [

this.DASH,

this.DOT,

this.DASH,

this.DASH

],

'z': [

this.DASH,

this.DASH,

this.DOT,

this.DOT

],

' ': [this.SPACE],

'1': [

this.DOT,

this.DASH,

this.DASH,

this.DASH,

this.DASH

],

'2': [

this.DOT,

this.DOT,

this.DASH,

this.DASH,

this.DASH

],

'3': [

this.DOT,

this.DOT,

this.DOT,

this.DASH,

this.DASH

],

'4': [

this.DOT,

this.DOT,

this.DOT,

this.DOT,

this.DASH

],

'5': [

this.DOT,

this.DOT,

this.DOT,

this.DOT,

this.DOT

],

'6': [

this.DASH,

this.DOT,

this.DOT,

this.DOT,

this.DOT

],

'7': [

this.DASH,

this.DASH,

this.DOT,

this.DOT,

this.DOT

],

'8': [

this.DASH,

this.DASH,

this.DASH,

this.DOT,

this.DOT

],

'9': [

this.DASH,

this.DASH,

this.DASH,

this.DASH,

this.DOT

],

'0': [

this.DASH,

this.DASH,

this.DASH,

this.DASH,

this.DASH

],

'.': [

this.DOT,

this.DASH,

this.DOT,

this.DASH,

this.DOT,

this.DASH

],

',': [

this.DASH,

this.DASH,

this.DOT,

this.DOT,

this.DASH,

this.DASH

],

'\'': [

this.DASH,

this.DOT,

this.DASH,

this.DOT,

this.DASH,

this.DOT

],

'!': [

this.DASH,

this.DOT,

this.DASH,

this.DOT,

this.DASH,

this.DASH

],

'-': [

this.DASH,

this.DOT,

this.DOT,

this.DOT,

this.DOT,

this.DASH

],

'&': [

this.DOT,

this.DASH,

this.DOT,

this.DOT,

this.DOT

],

'?': [

this.DOT,

this.DOT,

this.DASH,

this.DASH,

this.DOT,

this.DOT

],

'/': [

this.DASH,

this.DOT,

this.DOT,

this.DASH,

this.DOT

],

'(': [

this.DASH,

this.DOT,

this.DASH,

this.DASH,

this.DOT

],

')': [

this.DASH,

this.DOT,

this.DASH,

this.DASH,

this.DOT,

this.DASH

],

':': [

this.DASH,

this.DASH,

this.DASH,

this.DOT,

this.DOT,

this.DOT

],

';': [

this.DASH,

this.DOT,

this.DASH,

this.DOT,

this.DASH,

this.DOT

],

'=': [

this.DASH,

this.DOT,

this.DOT,

this.DOT,

this.DASH

],

'+': [

this.DOT,

this.DASH,

this.DOT,

this.DASH,

this.DOT

],

'_': [

this.DOT,

this.DOT,

this.DASH,

this.DASH,

this.DOT,

this.DASH

],

'"': [

this.DOT,

this.DASH,

this.DOT,

this.DOT,

this.DASH,

this.DOT

],

'$': [

this.DOT,

this.DOT,

this.DOT,

this.DASH,

this.DOT,

this.DOT,

this.DASH

],

'@': [

this.DOT,

this.DASH,

this.DASH,

this.DOT,

this.DASH,

this.DOT

]

};

};

$traceurRuntime.createClass(MorseCode, {

parse: function(input) {

input = input.split('');

for (var i = 0, ii = input.length; i < ii; i++) {

input[i] = {

original: input[i].toLowerCase(),

sequence: this.map[input[i].toLowerCase()]

};

}

console.log(input);

return input;

},

humanReadable: function(input) {

var text = ' ';

input = this.parse(input);

for (var i = 0, ii = input.length; i < ii; i++) {

var current = input[i];

for (var c = 0, cc = current.sequence.length; c < cc; c++) {

var char;

switch (current.sequence[c]) {

case this.SPACE:

char = '\n';

break;

case this.DOT:

char = '\u2022';

break;

case this.DASH:

char = '\u2013';

}

text += char;

}

text += ' ';

}

console.log(text);

return text;

}

}, {});

var morseCode = new MorseCode();

var input = $('textarea.input');

var run = $('button.run');

var output = $('pre.output');

var clear = $('button.clear');

run.on('click', function(e) {

var inputText = input.val();

console.log('run');

output.text(morseCode.humanReadable(inputText));

});

clear.on('click', function(e) {

input.val('');

output.text('');

});

C语言程序设计中的摩斯电码音频解码器通常涉及到两个主要步骤:首先,将接收到的摩斯电码文本转换为可理解的信息(字符或单词),然后,如果需要,播放这些信息作为音频信号。由于这是一个相对复杂的项目,我会提供一个简化的示例代码框架,你可以根据实际需求扩展。 ```c #include <stdio.h> #include <string.h> #include <ctype.h> #include <waveapi.h> // 如果你需要处理音频 // 摩斯电码字典 char morse_code[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "...", "-", "..-", "...-", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." }; // 解码函数 void decode_morse(char *morse, char *decoded) { int i, j, k; for (i = 0; morse[i] != '\0'; i += 2) { if (isalpha(morse[i])) { decoded[k++] = tolower(morse[i]); } else { for (j = 0; morse[i + j + 1] != '\0'; j++) { decoded[k++] = morse_code[morse[i] - 'A']; decoded[k++] = morse_code[morse[i + j + 1] - 'A']; } } } decoded[k] = '\0'; } int main() { char input_morse[] = ".... . .-.. .-.. --- / .---- ..--- ...--"; char output_text[100]; decode_morse(input_morse, output_text); printf("Decoded message: %s\n", output_text); // 示例音频部分,这里仅作演示(可能需要链接到音频库) // WAV音频文件处理 // WaveInCapabilities caps; // WaveInOpen(&waveHandle, ..., &caps); // waveDataBuffer[dataLength] = ...; // 假设已经填充了解码后的文字对应的音频样本 // WaveInWrite(waveHandle, waveDataBuffer, dataLength); // WaveInClose(waveHandle); return 0; } ``` 这个代码是一个基本的框架,用于将输入的摩斯电码字符串转换成ASCII文本。对于音频解码部分,我假设了一个`WaveIn*`结构体,这在Windows API中用于读取WAV音频文件。实际操作中,你可能需要引入音频处理库,如PortAudio或libavcodec,来生成和播放音频。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值