Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
|
|
@ -1,39 +0,0 @@
|
|||
/* Record_sound.wren */
|
||||
|
||||
class C {
|
||||
foreign static getInput(maxSize)
|
||||
|
||||
foreign static arecord(args)
|
||||
|
||||
foreign static aplay(name)
|
||||
}
|
||||
|
||||
var name = ""
|
||||
while (name == "") {
|
||||
System.write("Enter output file name (without extension) : ")
|
||||
name = C.getInput(80)
|
||||
}
|
||||
name = name + ".wav"
|
||||
|
||||
var rate = 0
|
||||
while (!rate || !rate.isInteger || rate < 2000 || rate > 192000) {
|
||||
System.write("Enter sampling rate in Hz (2000 to 192000) : ")
|
||||
rate = Num.fromString(C.getInput(6))
|
||||
}
|
||||
var rateS = rate.toString
|
||||
|
||||
var dur = 0
|
||||
while (!dur || dur < 5 || dur > 30) {
|
||||
System.write("Enter duration in seconds (5 to 30) : ")
|
||||
dur = Num.fromString(C.getInput(5))
|
||||
}
|
||||
var durS = dur.toString
|
||||
|
||||
System.print("\nOK, start speaking now...")
|
||||
// Default arguments: -c 1, -t wav. Note only signed 16 bit format supported.
|
||||
var args = ["-r", rateS, "-f", "S16_LE", "-d", durS, name]
|
||||
C.arecord(args.join(" "))
|
||||
|
||||
System.print("\n'%(name)' created on disk and will now be played back...")
|
||||
C.aplay(name)
|
||||
System.print("\nPlay-back completed.")
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdio_ext.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "wren.h"
|
||||
|
||||
void C_getInput(WrenVM* vm) {
|
||||
int maxSize = (int)wrenGetSlotDouble(vm, 1) + 2;
|
||||
char input[maxSize];
|
||||
fgets(input, maxSize, stdin);
|
||||
__fpurge(stdin);
|
||||
input[strcspn(input, "\n")] = 0;
|
||||
wrenSetSlotString(vm, 0, (const char*)input);
|
||||
}
|
||||
|
||||
void C_arecord(WrenVM* vm) {
|
||||
const char *args = wrenGetSlotString(vm, 1);
|
||||
char command[strlen(args) + 8];
|
||||
strcpy(command, "arecord ");
|
||||
strcat(command, args);
|
||||
system(command);
|
||||
}
|
||||
|
||||
void C_aplay(WrenVM* vm) {
|
||||
const char *name = wrenGetSlotString(vm, 1);
|
||||
char command[strlen(name) + 6];
|
||||
strcpy(command, "aplay ");
|
||||
strcat(command, name);
|
||||
system(command);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn bindForeignMethod(
|
||||
WrenVM* vm,
|
||||
const char* module,
|
||||
const char* className,
|
||||
bool isStatic,
|
||||
const char* signature) {
|
||||
if (strcmp(module, "main") == 0) {
|
||||
if (strcmp(className, "C") == 0) {
|
||||
if (isStatic && strcmp(signature, "getInput(_)") == 0) return C_getInput;
|
||||
if (isStatic && strcmp(signature, "arecord(_)") == 0) return C_arecord;
|
||||
if (isStatic && strcmp(signature, "aplay(_)") == 0) return C_aplay;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void writeFn(WrenVM* vm, const char* text) {
|
||||
printf("%s", text);
|
||||
}
|
||||
|
||||
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
|
||||
switch (errorType) {
|
||||
case WREN_ERROR_COMPILE:
|
||||
printf("[%s line %d] [Error] %s\n", module, line, msg);
|
||||
break;
|
||||
case WREN_ERROR_STACK_TRACE:
|
||||
printf("[%s line %d] in %s\n", module, line, msg);
|
||||
break;
|
||||
case WREN_ERROR_RUNTIME:
|
||||
printf("[Runtime Error] %s\n", msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char *readFile(const char *fileName) {
|
||||
FILE *f = fopen(fileName, "r");
|
||||
fseek(f, 0, SEEK_END);
|
||||
long fsize = ftell(f);
|
||||
rewind(f);
|
||||
char *script = malloc(fsize + 1);
|
||||
fread(script, 1, fsize, f);
|
||||
fclose(f);
|
||||
script[fsize] = 0;
|
||||
return script;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
WrenConfiguration config;
|
||||
wrenInitConfiguration(&config);
|
||||
config.writeFn = &writeFn;
|
||||
config.errorFn = &errorFn;
|
||||
config.bindForeignMethodFn = &bindForeignMethod;
|
||||
WrenVM* vm = wrenNewVM(&config);
|
||||
const char* module = "main";
|
||||
const char* fileName = "Record_sound.wren";
|
||||
char *script = readFile(fileName);
|
||||
WrenInterpretResult result = wrenInterpret(vm, module, script);
|
||||
switch (result) {
|
||||
case WREN_RESULT_COMPILE_ERROR:
|
||||
printf("Compile Error!\n");
|
||||
break;
|
||||
case WREN_RESULT_RUNTIME_ERROR:
|
||||
printf("Runtime Error!\n");
|
||||
break;
|
||||
case WREN_RESULT_SUCCESS:
|
||||
break;
|
||||
}
|
||||
wrenFreeVM(vm);
|
||||
free(script);
|
||||
return 0;
|
||||
}
|
||||
20
Task/Record-sound/Wren/record-sound.wren
Normal file
20
Task/Record-sound/Wren/record-sound.wren
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import "os" for Process
|
||||
import "./ioutil" for Input
|
||||
|
||||
var name = Input.text("Enter output file name (without extension) : ", 1, 80)
|
||||
name = name + ".wav"
|
||||
|
||||
var rate = Input.integer("Enter sampling rate in Hz (2000 to 192000) : ", 2000, 192000)
|
||||
var rateS = rate.toString
|
||||
|
||||
var dur = Input.number("Enter duration in seconds (5 to 30) : ", 5, 30)
|
||||
var durS = dur.toString
|
||||
|
||||
System.print("\nOK, start speaking now...")
|
||||
// Default arguments: -c 1, -t wav. Note only signed 16 bit format supported.
|
||||
var args = ["-r", rateS, "-f", "S16_LE", "-d", durS, name]
|
||||
Process.exec("arecord", args)
|
||||
|
||||
System.print("\n'%(name)' created on disk and will now be played back...")
|
||||
Process.exec("aplay %(name)")
|
||||
System.print("\nPlay-back completed.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue