NestarZ
NestarZ
Explore posts from servers
DDeno
Created by NestarZ on 5/8/2024 in #help
Like import.meta.resolve("./bla/bla") but so that it return me the relative cwd path
How using Deno to do something like import.meta.resolve("./bla/bla") but so that it return me the relative path relative to the current working directory ?
4 replies
DDeno
Created by NestarZ on 2/29/2024 in #help
Why JSX is not working ?
// @deno-types="@types/react" import React from "react"; const A = (): React.ReactElement => <div />; const B = (): React.ReactElement => <A />; TS2786 [ERROR]: 'A' cannot be used as a JSX component. Its type '() => React.ReactElement' is not a valid JSX element type. Type '() => React.ReactElement' is not assignable to type '(props: any, deprecatedLegacyContext?: any) => ReactNode'. Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'. Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'. const B = (): React.ReactElement => <A />; ^ at file:///Users/elias/code/bureaudouble/bureau/src/routes/Home.tsx:23:38 'children' is declared here. children: ReactNode; ~~~~ at file:///Users/Library/Caches/deno/npm/registry.npmjs.org/@types/react/18.2.57/index.d.ts:326:9
3 replies
DDeno
Created by NestarZ on 2/24/2024 in #help
How to apply @deno-types on a dynamic import
// @deno-types="npm:@types/react-dom@18/client"
const { hydrateRoot: hydrate } = (await import("react-dom/client")).default;
// @deno-types="npm:@types/react-dom@18/client"
const { hydrateRoot: hydrate } = (await import("react-dom/client")).default;
Is not working, how to apply @Deno-types on a dynamic import ? I get this error: Check file:///Users/code/bureau/mod.ts error: Uncaught Error: Failed resolving package subpath './client' for '/Users/Library/Caches/deno/npm/registry.npmjs.org/react-dom/18.2.0/package.json': [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './client' is not defined for types by "exports" in '/Users/Library/Caches/deno/npm/registry.npmjs.org/react-dom/18.2.0/package.json' imported from '/Users/code/bureau/src/lib.ts'
4 replies
DDeno
Created by NestarZ on 11/18/2023 in #help
Preact Hello World is not working
/** @jsxImportSource https://esm.sh/preact */ import { useState } from "https://esm.sh/preact/hooks"; export const A = () => { const [d] = useState(1); return ( <div> {d} </div> ); }; const v = A(); I'm trying to start this simple program but it leads to error: Uncaught TypeError: Cannot read properties of undefined (reading '__H') Can you help me please ? I'm running it using deno run -A test.tsx
3 replies
DDeno
Created by NestarZ on 5/22/2023 in #help
Deno.readDir on current script even if used like an http package.
Hello !! I would like to do Deno.readDir and readFiles on files relative to the script that execute Deno.readDir even if the script lives in deno.land/x. How should I do it ? Any help is welcomed thank you.
2 replies
DDeno
Created by NestarZ on 2/15/2023 in #help
Python alternative to ctypes, can't figure how to convert a code
Hello, I am trying to convert a Python ctypes code to Deno using FFI, but can't know why its not working
import ctypes

class WhisperFullParams(ctypes.Structure):
_fields_ = [
("strategy", ctypes.c_int),
#
("n_max_text_ctx", ctypes.c_int),
("n_threads", ctypes.c_int),
("offset_ms", ctypes.c_int),
("duration_ms", ctypes.c_int)

whisper.whisper_init_from_file.restype = ctypes.c_void_p
whisper.whisper_full_default_params.restype = WhisperFullParams
whisper.whisper_full_get_segment_text.restype = ctypes.c_char_p

# initialize whisper.cpp context
ctx = whisper.whisper_init_from_file(fname_model.encode("utf-8"))

# get default whisper parameters and adjust as needed
params = whisper.whisper_full_default_params()
params.print_realtime = True
params.print_progress = False

# load WAV file
samplerate, data = wavfile.read(fname_wav)

# convert to 32-bit float
data = data.astype("float32") / 32768.0

# run the inference
result = whisper.whisper_full(
ctypes.c_void_p(ctx),
params,
data.ctypes.data_as(ctypes.POINTER(ctypes.c_float)),
len(data),
)
import ctypes

class WhisperFullParams(ctypes.Structure):
_fields_ = [
("strategy", ctypes.c_int),
#
("n_max_text_ctx", ctypes.c_int),
("n_threads", ctypes.c_int),
("offset_ms", ctypes.c_int),
("duration_ms", ctypes.c_int)

whisper.whisper_init_from_file.restype = ctypes.c_void_p
whisper.whisper_full_default_params.restype = WhisperFullParams
whisper.whisper_full_get_segment_text.restype = ctypes.c_char_p

# initialize whisper.cpp context
ctx = whisper.whisper_init_from_file(fname_model.encode("utf-8"))

# get default whisper parameters and adjust as needed
params = whisper.whisper_full_default_params()
params.print_realtime = True
params.print_progress = False

# load WAV file
samplerate, data = wavfile.read(fname_wav)

# convert to 32-bit float
data = data.astype("float32") / 32768.0

# run the inference
result = whisper.whisper_full(
ctypes.c_void_p(ctx),
params,
data.ctypes.data_as(ctypes.POINTER(ctypes.c_float)),
len(data),
)
I am looking for a bit of help, any would be gladly welcomed ! For now the code just hang when calling whisper.whisper_full_default_params
3 replies