Author Topic: Spell It Aloud (Help Requested)  (Read 11151 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Spell It Aloud (Help Requested)
« on: July 28, 2019, 02:23:39 pm »
Code: [Select]
SoundDir$ = ".\Alphabet Sounds\"

DIM AlphaSound(65 TO 90)
FOR i = 65 TO 90
    temp$ = SoundDir$ + CHR$(i) + ".ogg"
    AlphaSound(i) = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
NEXT

DO
    INPUT "Input word to spell aloud: "; word$
    IF word$ = "" THEN SYSTEM
    word$ = UCASE$(word$)
    FOR i = 1 TO LEN(word$)
        _SNDPLAY AlphaSound(ASC(word$, i))
        _DELAY 1
    NEXT
LOOP

My niece recently just gave birth to a lovely little girl (8 lbs 3 ozs), and I was thinking of a simple little program to help them learn to read and write in a few years.  What I've came up with is a very nice little concept  (at least, I think it is):

Step 1: Let the user download some free images from the internet (such as a cat or dog, or such), and then save them with that filename.
Step 2: The program should look in the folder for those image files, and then pop the picture up on the screen, and then place them on the screen for us, along with their letters.  It should then read those letters back to us, to help a child familiarize themselves with the images of those letters on the screen, and how they correspond to each other.

What we have here is just a demo of taking a word and spelling it out aloud for the user, but I plan to expand upon it later so it'll do as described above.  My question to you guys is:

1) Is there someone who wants to record their voice saying various words and share them for this project?  I've got a speech impediment which sometimes slurs some of my spoken words (which is one reason, I suppose, why I turned to writing as a means to get my thoughts and ideas across to the world), so just some simple *.ogg recordings of "cat", "dog", "frog", and so on would be appreciated.

2) Anyone have a good source for low resolution images of simple words?  I don't need a million large images to package with this little program; small ones which represent the image will work nicely -- but they need to be copywrite free/open.

3) This should work quite easily for nouns and such, but does anyone have an idea how we'd represent an ACTION like this?  How do we convey the concept of "run", "bounce", "fall"?

All-in-all, it seems like a simple enough concept to pull off for a program; just a little time consuming to gather various images to showcase our words....

Anywho, I thought I'd share the concept and see if anyone would be interested in helping me to assemble a simple little program like this.  ;)
* Alphabet Sounds.7z (Filesize: 99.48 KB, Downloads: 205)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #1 on: July 28, 2019, 04:15:19 pm »
As you surely found out from my writing, so with my English (written) is it no glory. And if I still had to say it ... maybe as a parody it could be a success, but that's not what you need.
 However, this idea caught my attention. Pictures would probably be enough in 256 colors. The moving things, well, I would solve the file name such as sprite-run, sprite-fall ... but here we encounter a technical problem, because the ordinary user does not download, as a programmer, the correct format sprite image, for example, 5 frames and two rows. Thus, sprite would have to be present in the program beforehand.  I thought of an improvement. Suppose the file is named "good brown dog .gif". It might be possible for the program to spell and print only the name since the last space (dog), according to the space in the name and the set level (brown dog) or at top level the full title. That's just an idea. Definitely, on pinterest I downloaded pictures to the meditation program, there are many free, another option is to download SVG and save part of the screen to compatible format.

Next idea - is on screen cat image? Press to it and play "meow" :-D This can be done with internal DATA block and included audio files...
(DATA CAT, meow.ogg, DOG, bark.ogg  ....)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #2 on: July 28, 2019, 04:24:02 pm »
And of course, congratulations, Uncle!!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Spell It Aloud (Help Requested)
« Reply #3 on: July 28, 2019, 07:39:07 pm »
Below is the actual working prototype of how I'd envision this little project coming together and working.

Now all I need is:

Tons of simple photos like the whopping three I've assembled so far,
And someone with a clear, easy to understand voice to speak the actual words so I can put them into another \sounds\ directory and load them so I can have the program talk to us like:

"C"
"A"
"T"
...
"CAT"
...
"C"
"A"
"T"

Speak the letters, say the word, Speak the letters again...



Once I get a good assortment of words and images, I'll probably have the program set up so you can run learning exercises with it...

Let it go through a cycle of 10 words, 3 times each (30 total images would go across the screen), and then pop an image up on the screen and ask, "Can you spell (insert image word here)?"  Let the child give it a shot, see how they do, and then score them just like in school.

Problem words can be saved to a list for future study, and passed words will go into a different list for review much later (like mid terms or final exams in schools).

All in all, I think this has the potential to be a nice little teaching tool for young children (or as a starting point for anyone who might want to learn the English language, for that matter.)

Try it out and tell me what you think of it guys.  :D
* Spell It Aloud.7z (Filesize: 1.57 MB, Downloads: 187)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #4 on: July 29, 2019, 01:14:36 am »
Have you tried places like vectorstock.com?

https://www.vectorstock.com/royalty-free-vector/surprised-emoji-with-a-mexican-hat-vector-20777258

https://www.vectorstock.com/royalty-free-vector/cartoon-man-with-two-rollers-paints-a-brick-wall-vector-24911576

I'm pretty sure that's a MAGA hat, in that one.

Oh, you wanted a cat... OK, got it... https://www.vectorstock.com/royalty-free-vector/halloween-black-cat-vector-1350256

Kidding aside, a lot less sites have free images these days and a lot of them are going to "For personal use only." I would consider what you want it for to be just that, but if you wanted to market it at some point, well, that's a horse of a different color. Anyway, 1,000? That will take you awhile.  I believe WGET has a newly added image search function, but I'm not sure if you could use it on sites like these. If it could point to only the free for personal use images, you could download all of them, and sort them out later. I made some kind of utility for this ages ago, just searching for the 3-letter extension of image files. Sure, you could get that off of Bing, Google, DuckDuckGo, etc., but again, you would be stumbling all over copyright issues, but if you could target only free images, you'd be golden.

Good luck, and congrats on the addition to the family.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #5 on: July 29, 2019, 11:14:43 am »
Steve, I used your last code as a base and I'm working on it. I downloaded some animals from Google, I deleted _DELAY 1 after _SNDPLAY and replaced it with DO WHILE _SNDPLAYING (array): LOOP..., add _CONTINUE if file name contains space and _DELAY .5 if is space to speech (guinea pig image) and working on it also now.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #6 on: July 29, 2019, 04:46:46 pm »
So, here is small upgrade. DEFLNG in begin DELETED because this do problems with new SUB GETNewWH (Get New Width and Height). Images now are not deformed. Tomorrow I will work on further improvements. All suggestions are very welcome. Tomorrow I want to make animal sounds by clicking the animal + add more photos.
* Spell it Aloud_U0.zip (Filesize: 3.3 MB, Downloads: 177)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Spell It Aloud (Help Requested)
« Reply #7 on: July 30, 2019, 11:59:34 am »
Petr, here's my next little upgrade to this little project:  Adding tags to images for ease of searching/referencing later.

Code: [Select]
SCREEN _NEWIMAGE(800, 600, 32)
_TITLE "Spell It Aloud"
DEFLNG A-Z
RANDOMIZE TIMER

CONST ImageDir$ = ".\Images\"
CONST SoundDir$ = ".\Alphabet Sounds\"



DIM AlphaSound(65 TO 90)
REDIM SHARED PhotoList(100000) AS STRING
REDIM SHARED PhotoTags(100000) AS STRING
DIM SHARED f AS LONG, f1 AS LONG

'load our fonts
f = _LOADFONT("courbd.ttf", 84, "MONOSPACE")
f1 = _LOADFONT("courbd.ttf", 20, "MONOSPACE")
_FONT f
fw = _FONTWIDTH: fh = _FONTHEIGHT


'Load the alphabet sound library
FOR i = 65 TO 90
    temp$ = SoundDir$ + CHR$(i) + ".ogg"
    AlphaSound(i) = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
NEXT

_FONT f
'Get a listing of the files
PhotoList$ = ImageDir$ + "*.bmp " + ImageDir$ + "*.jpg " + ImageDir$ + "*.png " + ImageDir$ + "*.gif "
SHELL _HIDE "DIR " + PhotoList$ + "/b /s /a-d >PhotoList.txt"

'Load those names into a file.
OPEN "Photolist.txt" FOR BINARY AS #1
DO UNTIL EOF(1)
    PhotoCount = PhotoCount + 1
    LINE INPUT #1, PhotoList(PhotoCount)
LOOP
REDIM _PRESERVE PhotoList(PhotoCount)
CLOSE

_DELAY 1 'Give everything a moment to initialize and get started for us.


DO
    DO UNTIL photochosen <> oldpic
        photochosen = INT(RND * PhotoCount) + 1
    LOOP
    oldpic = photochosen
    word$ = UCASE$(PhotoList(photochosen))
    word$ = MID$(word$, _INSTRREV(word$, "\") + 1)
    word$ = LEFT$(word$, INSTR(word$, ".") - 1)

    IF tempimage <> 0 THEN _FREEIMAGE tempimage 'free the old image
    tempimage = _LOADIMAGE(PhotoList(photochosen), 32) 'get the new image

    GetTags word$

    CLS
    _PUTIMAGE (50, 50)-(750, 500), tempimage 'Put the image to the screen
    ShowTags 'Display the tags up top

    'Put the letters to the screen one by one
    pw = _PRINTWIDTH(word$): StartX = (_WIDTH - pw) \ 2 'center position

    FOR i = 1 TO LEN(word$)
        a = ASC(word$, i) AND NOT 32 'play lowercase letters as uppercase sounds
        _PRINTSTRING (StartX + (i - 1) * fw, 510), MID$(word$, i, 1)
        IF a < 65 OR a > 90 THEN _CONTINUE 'ignore non-letters in the file name
        _SNDPLAY AlphaSound(a)
        WHILE _SNDPLAYING(AlphaSound(a)) 'wait for sound to finish before playing again
            _LIMIT 10 'play nice with CPU during wait
        WEND
    NEXT
    DO
        k = _KEYHIT
        _KEYCLEAR
        _LIMIT 10
        SELECT CASE k
            CASE 65, 97 'a,A
                AddTags word$
            CASE 68, 100 'd,D
                DeleteTags word$
            CASE 32 'space
                _DELAY 1
                EXIT DO
            CASE 27 'escape
                SYSTEM 'quit
        END SELECT
    LOOP
LOOP


SUB BlankTop
    LINE (0, 0)-(799, 49), &HFF000000, BF 'blank out the top info
END SUB

SUB AddTags (tfile$)
    BlankTop
    _FONT f1
    LOCATE 1, 1: PRINT "Add Tag:";
    INPUT tag$
    IF tag$ <> "" THEN
        u = UBOUND(phototags)
        FOR i = 1 TO u
            IF _STRICMP(tag$, PhotoTags(i)) = 0 THEN TagExists = -1: EXIT FOR
        NEXT
        IF NOT TagExists THEN
            REDIM _PRESERVE PhotoTags(u + 1) AS STRING
            PhotoTags(u + 1) = tag$

            file$ = ".\Images\" + tfile$ + ".txt"
            OPEN file$ FOR OUTPUT AS #1
            FOR i = 1 TO u + 1
                PRINT #1, "#";
                PRINT #1, PhotoTags(i);
                PRINT #1, " ";
            NEXT
            CLOSE
        END IF
    END IF
    ShowTags
    _FONT f
END SUB

SUB DeleteTags (tfile$)
    BlankTop
    _FONT f1
    LOCATE 1, 1: PRINT "Delete Tag:";
    INPUT tag$
    IF tag$ <> "" THEN
        u = UBOUND(phototags)
        FOR i = 1 TO u
            IF _STRICMP(tag$, PhotoTags(i)) = 0 THEN TagExists = -1: EXIT FOR
        NEXT
        IF TagExists THEN
            FOR j = i TO u - 1
                PhotoTags(j) = PhotoTags(j + 1)
            NEXT
            REDIM _PRESERVE PhotoTags(u - 1) AS STRING
            file$ = ".\Images\" + tfile$ + ".txt"
            OPEN file$ FOR OUTPUT AS #1
            FOR i = 1 TO u - 1
                PRINT #1, "#";
                PRINT #1, PhotoTags(i);
                PRINT #1, " ";
            NEXT
            CLOSE
        END IF
    END IF
    ShowTags
    _FONT f
END SUB


SUB GetTags (tfile$)
    'Load the PhotoTags
    file$ = ".\Images\" + tfile$ + ".txt"
    OPEN file$ FOR BINARY AS #1
    IF LOF(1) = 0 THEN 'if there's no tags, we can't get them.
        CLOSE
        REDIM _PRESERVE PhotoTags(0) AS STRING
        EXIT SUB
    END IF
    DO UNTIL EOF(1)
        LINE INPUT #1, junk$
        l = 1
        DO UNTIL l = 0
            l = INSTR(junk$, "#")
            IF l THEN
                junk$ = MID$(junk$, l + 1)
                l1 = INSTR(junk$, "#")
                IF l1 = 0 THEN 'nothing more, we now have the tag
                    tag$ = junk$
                    l = 0
                ELSE
                    tag$ = LEFT$(junk$, l1 - 1)
                    junk$ = MID$(junk$, l1)
                END IF
            END IF
            tag$ = _TRIM$(tag$) 'no leading/tailing spaces for ease of matching
            TagFound = 0
            FOR i = 1 TO TagCount 'Check the existing tags to see if these exist
                IF PhotoTags(i) = tag$ THEN TagFound = -1: EXIT FOR
            NEXT
            IF NOT TagFound THEN 'If not, add the new tags to the list
                TagCount = TagCount + 1
                IF TagCount > UBOUND(PhotoTags) THEN REDIM _PRESERVE PhotoTags(TagCount + 1000) AS STRING
                PhotoTags(TagCount) = tag$
            END IF
        LOOP
    LOOP
    CLOSE
    REDIM _PRESERVE PhotoTags(TagCount) AS STRING
END SUB

SUB ShowTags
    BlankTop
    _FONT f1
    PRINT UBOUND(phototags); " TAGS: "
    FOR i = 1 TO UBOUND(Phototags)
        PRINT "#"; PhotoTags(i); " ";
    NEXT

    _FONT f
END SUB

When a picture is now loaded, the program should either read the tag file, or else create a blank one for it.  You can easily add tags by hitting the A key, and delete them with the D key, before moving on to the next image.

Later, I foresee adding in a routine to allow the user to limit results via tags, so they can create "custom-style lesson plans" for children.  I think here would be a good place to grab word lists to organize by year/week to create lesson plans for children:  https://www.k12reader.com/worksheet/first-grade-master-spelling-list/view/

For example:  Sight words and -at family words
1. the
2. of
3. and
4. that
5. cat
6. mat
7. sat
8. hat

Some of those would be hard to represent with pictures alone (the, of, and, that), but the cat, hat, mat easily and readily fits the format of this little program.

By adding tags such as #Year1 #AT_Word #Week1, we can fix it so that an user could search for those things and have only them pop up for a "study guide", to help a child learn those items.

"cat" might have the tags: #Year1 #AT_Word #Week1 #Animal #Pet #Cute #Fluffy (and whatever else we want to describe it with), so later the user can enter their search tags and easily create a custom-list of photos for their child to spell and look at.  :)



You're going the route of adding sounds to the program; I thought  I'd take the steps towards making us a searchable tag-system for ease of usability.  Between the both of us, we may end up with a really nice little teaching tool out of this project.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #8 on: July 30, 2019, 12:13:56 pm »
Hi Steve, I've been working on it too - my way. I'm posting what I just wrote in ZIP format, i  look at what you wrote and me give it together. At the end of the source code, when you look at the last line of commented lines, you will know what I was about to do. :)

* Spell it Aloud2.zip (Filesize: 6.97 MB, Downloads: 163)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #9 on: July 30, 2019, 12:23:13 pm »
:)
work in progress.jpg

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #10 on: July 30, 2019, 12:49:45 pm »
Here is mix both sources with your + my functionality:

Code: [Select]

'Steve's idea: 10 different words, each of which is repeated three times and then one is picked and the child writes image name
'(text input, I suppose, because QB64 does not have microphone support)?




SCREEN _NEWIMAGE(800, 600, 32)
_TITLE "Spell It Aloud"
RANDOMIZE TIMER

ImageDir$ = ".\Images\"
SoundDir$ = ".\Alphabet Sounds\"


DIM SHARED AlphaSound(65 TO 90), f AS LONG, f1 AS LONG
REDIM SHARED PhotoList(100000) AS STRING
REDIM SHARED PhotoTags(100000) AS STRING
REDIM SHARED IMG10(9) AS LONG 'array fo 10 different images. Contains diferent indexes numbers for PhotoList()


'load our fonts
f = _LOADFONT("courbd.ttf", 84, "MONOSPACE")
f1 = _LOADFONT("courbd.ttf", 20, "MONOSPACE")
_FONT f
fw = _FONTWIDTH: fh = _FONTHEIGHT


'Load the alphabet sound library
FOR i = 65 TO 90
    temp$ = SoundDir$ + CHR$(i) + ".ogg"
    AlphaSound(i) = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
NEXT

'Get a listing of the files
PhotoList$ = ImageDir$ + "*.bmp " + ImageDir$ + "*.jpg " + ImageDir$ + "*.png " + ImageDir$ + "*.gif "
SHELL _HIDE "DIR " + PhotoList$ + "/b /s /a-d >PhotoList.txt"

'Load those names into a file.
OPEN "Photolist.txt" FOR BINARY AS #1
DO UNTIL EOF(1)
    PhotoCount = PhotoCount + 1
    LINE INPUT #1, PhotoList(PhotoCount)
LOOP
CLOSE #1
REDIM _PRESERVE PhotoList(PhotoCount)


_DELAY 1 'Give everything a moment to initialize and get started for us.



Insert_10_Different_Images 'insert 10 different indexes numbers from PhotoList, to array IMG10() [LONG] [0..9]

DO


    '    DO UNTIL photochosen <> oldpic
    '        RANDOMIZE TIMER
    '       photochosen = INT(RND * PhotoCount) + 1
    '  LOOP
    '  oldpic = photochosen

    photochosen = IMG10(index)
    index = index + 1
    IF index > 9 THEN index = INT(1 + RND * 8): Query = 1



    word$ = UCASE$(PhotoList(photochosen))
    word$ = MID$(word$, _INSTRREV(word$, "\") + 1)
    word$ = LEFT$(word$, INSTR(word$, ".") - 1)
    IF tempimage < -1 THEN _FREEIMAGE tempimage
    tempimage = _LOADIMAGE(PhotoList(photochosen), 32)

    GetTags word$
    'Put the image to the screen                                UPGRADE


    FOR Loop_it = 1 TO 3 'as you say. 3x one word + image, this 10x with different images an then query.

        CLS
        'program photo area is 700 x 450 pixels. So:
        GetNewWH 700, 450, tempimage, nW, nH


        Ws = 400 - (nW / 2)
        We = 400 + (nW / 2)
        Hs = 300 - (nH / 2) - 25
        He = 300 + (nH / 2) - 25

        _PUTIMAGE (Ws, Hs)-(We, He), tempimage
        ShowTags 'Display the tags up top


        'Put the letters to the screen one by one
        pw = _PRINTWIDTH(word$)
        StartX = (_WIDTH - pw) \ 2


        IF Query = 0 THEN 'as you need: 10x 3 words and then query to image name
            FOR i = 1 TO LEN(word$)
                a = ASC(word$, i) AND NOT 32
                _PRINTSTRING (StartX + (i - 1) * fw, 510), MID$(word$, i, 1)
                IF ASC(word$, i) = 32 THEN _DELAY .5: _CONTINUE
                IF a < 65 OR a > 90 THEN _CONTINUE
                _SNDPLAY AlphaSound(ASC(word$, i))
                DO WHILE _SNDPLAYING(AlphaSound(ASC(word$, i))): LOOP ' UPGRADE
            NEXT
        ELSE

            oldFont = _FONT
            _FONT 16
            'is time to query.....none _INPUTSTRING statement.... :)   i am so lasy!!!!!
            _PRINTSTRING (10, 510), "Insert image name: "

            DO UNTIL inpt$ = CHR$(13)
                inpt$ = INKEY$
                IF INT(TIMER) MOD 2 = 0 THEN cursor$ = "_" ELSE cursor$ = ""
                IF LEN(inpt$) THEN
                    word2$ = word2$ + UCASE$(inpt$)
                    IF inpt$ = CHR$(9) THEN word2$ = LEFT$(word2$, LEN(word2$) - 1) 'backspace
                END IF
                _PRINTSTRING (10 + (20 * 8), 510), word2$ + cursor$
            LOOP

            ok$ = "Correct!"
            okl = _PRINTWIDTH(ok$)
            word2$ = MID$(word2$, 1, LEN(word2$) - 1) 'erase CHR$(13) - ENTER from this word
            IF UCASE$(_TRIM$(word2$)) = UCASE$(_TRIM$(word$)) THEN
                _FONT oldFont
                StartX = _WIDTH / 2 - okl / 2
                _PRINTSTRING (StartX, 510), ok$
                SLEEP 2

            END IF
            Query = 0
            Insert_10_Different_Images
            _FONT oldFont
            index = 0
            _CONTINUE
        END IF '  if query condition


        WordPlay word$


        DO
            WHILE _MOUSEINPUT: WEND
            MX = _MOUSEX
            MY = _MOUSEY
            IF MX > Ws AND MX < We AND MY > Hs AND MY < He THEN
                IF _FILEEXISTS(_CWD$ + "\animal sounds\" + word$ + ".mp3") THEN
                    _MOUSESHOW "link"
                    IF _MOUSEBUTTON(1) THEN AnimalSound word$
                END IF

            ELSE
                _MOUSESHOW "default"
            END IF

            'keyboard access
            k = _KEYHIT
            _KEYCLEAR
            _LIMIT 10
            SELECT CASE k
                CASE 65, 97 'a,A
                    AddTags word$
                CASE 68, 100 'd,D
                    DeleteTags word$

                CASE 32 'space
                    '                _DELAY 1
                    SLEEP 1 '                                      Better for testing it
                    EXIT DO
                CASE 27 'escape
                    SYSTEM 'quit
            END SELECT
        LOOP
    NEXT Loop_it

LOOP


SUB AnimalSound (Word$)
    ASound$ = _CWD$ + "\animal sounds\" + Word$ + ".mp3"
    aAsound = _SNDOPEN(ASound$)
    _SNDPLAY aAsound
    DO WHILE _SNDPLAYING(aAsound)
        IF LEN(INKEY$) THEN _SNDSTOP (aAsound): EXIT DO
    LOOP
    _SNDCLOSE aAsound
    _MOUSESHOW "default"
END SUB




SUB GetNewWH (destWidth, destHeight, handle AS LONG, NewWidth, NewHeight) 'Sub return in variables NewWidth and NewHeight new image Width and image Height with the same ratio for optimal picture to set area width and height with [destWidth, destHeight]
    W = _WIDTH(handle)
    H = _HEIGHT(handle)
    Pw = W / destWidth
    Ph = H / destHeight
    IF W > H THEN P = Pw ELSE P = Ph
    NewWidth = W / P
    NewHeight = H / P
END SUB


SUB Insert_10_Different_Images 'place 10 different indexes from array PhotoList
    Max = UBOUND(photolist) 'PhotoList [1..?]
    REDIM IMG10(9) AS LONG
    pass = 0
    DIM i_nr AS INTEGER
    DO UNTIL pass = 10
        st:
        RANDOMIZE TIMER
        i_nr = 1 + RND * Max

        FOR t = 0 TO 9
            IF IMG10(t) = i_nr THEN GOTO st
        NEXT t

        FOR t = 0 TO 9
            IF IMG10(t) = 0 THEN IMG10(t) = i_nr: pass = pass + 1: EXIT FOR
        NEXT t
    LOOP
END SUB



SUB WordPlay (W AS STRING) 'will be replaced to my own mp3..... i never learn english, BUT I TRY IT.
    'path$ = _CWD$ + "\Words\" + W$ + ".mp3"
    'Word = _SNDOPEN(path$)
    '_SNDPLAY Word
    'DO WHILE _SNDPLAYING(Word): LOOP



    FOR l = 1 TO LEN(W)
        char = ASC(W, l)
        IF char = 32 THEN _DELAY .5: _CONTINUE
        _SNDPLAY AlphaSound(char)
        _DELAY .35
    NEXT l
END SUB


SUB BlankTop
    LINE (0, 0)-(799, 49), &HFF000000, BF 'blank out the top info
END SUB

SUB AddTags (tfile$)
    BlankTop
    _FONT f1
    LOCATE 1, 1: PRINT "Add Tag:";
    INPUT tag$
    IF tag$ <> "" THEN
        u = UBOUND(phototags)
        FOR i = 1 TO u
            IF _STRICMP(tag$, PhotoTags(i)) = 0 THEN TagExists = -1: EXIT FOR
        NEXT
        IF NOT TagExists THEN
            REDIM _PRESERVE PhotoTags(u + 1) AS STRING
            PhotoTags(u + 1) = tag$

            file$ = ".\Images\" + tfile$ + ".txt"
            OPEN file$ FOR OUTPUT AS #1
            FOR i = 1 TO u + 1
                PRINT #1, "#";
                PRINT #1, PhotoTags(i);
                PRINT #1, " ";
            NEXT
            CLOSE
        END IF
    END IF
    ShowTags
    _FONT f
END SUB

SUB DeleteTags (tfile$)
    BlankTop
    _FONT f1
    LOCATE 1, 1: PRINT "Delete Tag:";
    INPUT tag$
    IF tag$ <> "" THEN
        u = UBOUND(phototags)
        FOR i = 1 TO u
            IF _STRICMP(tag$, PhotoTags(i)) = 0 THEN TagExists = -1: EXIT FOR
        NEXT
        IF TagExists THEN
            FOR j = i TO u - 1
                PhotoTags(j) = PhotoTags(j + 1)
            NEXT
            REDIM _PRESERVE PhotoTags(u - 1) AS STRING
            file$ = ".\Images\" + tfile$ + ".txt"
            OPEN file$ FOR OUTPUT AS #1
            FOR i = 1 TO u - 1
                PRINT #1, "#";
                PRINT #1, PhotoTags(i);
                PRINT #1, " ";
            NEXT
            CLOSE
        END IF
    END IF
    ShowTags
    _FONT f
END SUB


SUB GetTags (tfile$)
    'Load the PhotoTags
    file$ = ".\Images\" + tfile$ + ".txt"
    OPEN file$ FOR BINARY AS #1
    IF LOF(1) = 0 THEN 'if there's no tags, we can't get them.
        CLOSE
        REDIM _PRESERVE PhotoTags(0) AS STRING
        EXIT SUB
    END IF
    DO UNTIL EOF(1)
        LINE INPUT #1, junk$
        l = 1
        DO UNTIL l = 0
            l = INSTR(junk$, "#")
            IF l THEN
                junk$ = MID$(junk$, l + 1)
                l1 = INSTR(junk$, "#")
                IF l1 = 0 THEN 'nothing more, we now have the tag
                    tag$ = junk$
                    l = 0
                ELSE
                    tag$ = LEFT$(junk$, l1 - 1)
                    junk$ = MID$(junk$, l1)
                END IF
            END IF
            tag$ = _TRIM$(tag$) 'no leading/tailing spaces for ease of matching
            TagFound = 0
            FOR i = 1 TO TagCount 'Check the existing tags to see if these exist
                IF PhotoTags(i) = tag$ THEN TagFound = -1: EXIT FOR
            NEXT
            IF NOT TagFound THEN 'If not, add the new tags to the list
                TagCount = TagCount + 1
                IF TagCount > UBOUND(PhotoTags) THEN REDIM _PRESERVE PhotoTags(TagCount + 1000) AS STRING
                PhotoTags(TagCount) = tag$
            END IF
        LOOP
    LOOP
    CLOSE
    REDIM _PRESERVE PhotoTags(TagCount) AS STRING
END SUB

SUB ShowTags
    BlankTop
    _FONT f1
    PRINT UBOUND(phototags); " TAGS: "
    FOR i = 1 TO UBOUND(Phototags)
        PRINT "#"; PhotoTags(i); " ";
    NEXT
    _FONT f
END SUB

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Spell It Aloud (Help Requested)
« Reply #11 on: July 31, 2019, 03:25:24 pm »
Petr -- See what you think of these changes as to the forward expansion of this little idea:

I've started to implement a better search/tag system for the images, allowing us to quickly and easily customize the images we show for the user.  The input routines are now working, but I need to add the save/change routine for the tags on the photos themselves...

Currently my time is rather limited (my wife is in the hospital again, with severe dehydration from "oozing ulcers" causing her extreme stomach issues), so I'm not able to push this project forward at the speed which I'd like to see it go -- but I'll eventually get to the finish line!  It'll just take a little longer than anticipated...  (...like usual. :P )

Demo.jpg
* Demo.jpg (Filesize: 50.07 KB, Dimensions: 806x629, Views: 248)
* Spell It Aloud.7z (Filesize: 1 MB, Downloads: 215)
« Last Edit: July 31, 2019, 03:33:29 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #12 on: July 31, 2019, 04:21:38 pm »
I am shocked. First attempt and program output is "DIE!"   -   good joke.  :)
Why in your color CONST you use unsigned long mark - this hexadecimal value is this type also without this mark

Wouldn't it be better to put the TAG search under the icon to activate it? Put a few icons on the right - to search for TAGs, to edit TAGs, to volume? It's just a suggestion. Is this the intention that only numbers can be entered when editing Photo Tags theme? I suppose he should go in there to enter the text?

If you want, I'll make those icon adjustments, and I would add some background. Tell me if you want to go the way when the TAG dialog will be right in the main window, or we'll complicate it a bit with icons (I can would do it tomorrow).




Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Spell It Aloud (Help Requested)
« Reply #13 on: July 31, 2019, 04:47:45 pm »
Colors should *always* be UNSIGNED LONG values.

Here’s why:

Code: [Select]
SCREEN _NEWIMAGE(800,600,32)
CONST White = &HFFFFFFFF ‘bright white
COLOR White

PSET (0,0), White

IF POINT(0,0) = White THEN
    PRINT “It matches”
ELSE
   PRINT “You broke your program!  Try UNSIGNED LONG instead!
END IF

POINT returns FLOAT values (and I have no idea why they’re not integer), and 1234567890 (Whatever the unsigned value actually is) is *NOT* equal to -1 (the signed value).

Think of it as _BYTE value vs _UNSIGNED _BYTE:


DIM b AS _UNSIGNED _BYTE
b = 1
IF b = NOT 0 THEN.....

NOT 0 is -1.
1 is not equal to -1.
That’s a FALSE if statement.

If you keep colors unsigned, you’ll save yourself a lot of headaches in the future.


As for layout/changes, give me a day or two to finish up things and get them functional, and then we can tweak them and move them around a bit.

If you look, the editor allows for both numbers and text in the tags.  Year is a number, as is Week, but Sound and Theme are both strings.

Think of cat as:  Year 1, Week 1, “AT”, “Animal”.

Cat, hat, bat, sat, pat, fat....  all these are “AT” words and contain the same sound.

Year/Week/Sound info can all be gathered from the lists here: https://www.k12reader.com/worksheet/first-grade-master-spelling-list/view/

Theme is just whatever seems to make sense.  Animal, Person, Vehicle, etc...



And if you look at the internal folders, you’ll even find my voice recorded now for “cat.MP3” and “is how you spell.MP3”.   I’ll try and add more words as time allows, since nobody is volunteering to be a pet “mike-monkey” for the project.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Spell It Aloud (Help Requested)
« Reply #14 on: July 31, 2019, 05:17:24 pm »
Yeah, like this. Aha! CONST not only passes the value but also the variable type! Okay then! I have a microphone, I promised, for the joke I will tell you tomorrow with my "English" and then I will send it to your email (only those files). Then you have fun, too.